summaryrefslogtreecommitdiffstats
path: root/content/renderer/media/media_stream_source_extra_data.h
blob: 4b88c147f8be3261cc862317bf124c92efed1931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_EXTRA_DATA_H_
#define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_EXTRA_DATA_H_

#include "base/callback.h"
#include "base/compiler_specific.h"
#include "content/common/content_export.h"
#include "content/common/media/media_stream_options.h"
#include "content/renderer/media/media_stream_source_observer.h"
#include "content/renderer/media/webrtc_audio_capturer.h"
#include "third_party/libjingle/source/talk/app/webrtc/videosourceinterface.h"
#include "third_party/WebKit/public/platform/WebMediaStreamSource.h"

namespace content {

class CONTENT_EXPORT MediaStreamSourceExtraData
    : NON_EXPORTED_BASE(public blink::WebMediaStreamSource::ExtraData) {
 public:
  typedef base::Callback<void(const blink::WebMediaStreamSource& source)>
      SourceStopCallback;

  MediaStreamSourceExtraData(const StreamDeviceInfo& device_info,
                             const SourceStopCallback& stop_callback);
  MediaStreamSourceExtraData();
  virtual ~MediaStreamSourceExtraData();

  // Return device information about the camera or microphone.
  const StreamDeviceInfo& device_info() const {
    return device_info_;
  }

  void SetVideoSource(webrtc::VideoSourceInterface* source) {
    video_source_ = source;
    source_observer_.reset(new MediaStreamSourceObserver(source, this));
  }

  void SetLocalAudioSource(webrtc::AudioSourceInterface* source) {
    local_audio_source_ = source;
    // TODO(perkj): Implement a local source observer for audio.
    // See |source_observer_|.
  }

  void SetAudioCapturer(WebRtcAudioCapturer* capturer) {
    DCHECK(!audio_capturer_);
    audio_capturer_ = capturer;
  }

  WebRtcAudioCapturer* GetAudioCapturer() const {
    // TODO(perkj): |audio_capturer_| can currently be reconfigured to use
    // another microphone even after it has been created since only one
    // capturer is supported. See issue crbug/262117.
    // It would make more sense if a WebRtcAudioCapturer represent one and only
    // one audio source.
    if (audio_capturer_ &&
        device_info_.session_id == audio_capturer_->session_id()) {
      return audio_capturer_;
    }
    return NULL;
  }

  webrtc::VideoSourceInterface* video_source() { return video_source_.get(); }
  webrtc::AudioSourceInterface* local_audio_source() {
    return local_audio_source_.get();
  }

  void OnLocalSourceStop();

 private:
  StreamDeviceInfo device_info_;

  scoped_refptr<webrtc::VideoSourceInterface> video_source_;

  // This member holds an instance of webrtc::LocalAudioSource. This is used
  // as a container for audio options.
  // TODO(hclam): This should be merged with |audio_source_| such that it
  // carries audio options.
  scoped_refptr<webrtc::AudioSourceInterface> local_audio_source_;
  scoped_ptr<MediaStreamSourceObserver> source_observer_;

  scoped_refptr<WebRtcAudioCapturer> audio_capturer_;

  SourceStopCallback stop_callback_;

  DISALLOW_COPY_AND_ASSIGN(MediaStreamSourceExtraData);
};

}  // namespace content

#endif  // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_EXTRA_DATA_H_