Home | History | Annotate | Download | only in media
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_EXTRA_DATA_H_
      6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_EXTRA_DATA_H_
      7 
      8 #include "base/callback.h"
      9 #include "base/compiler_specific.h"
     10 #include "content/common/content_export.h"
     11 #include "content/common/media/media_stream_options.h"
     12 #include "content/renderer/media/media_stream_source_observer.h"
     13 #include "content/renderer/media/webrtc_audio_capturer.h"
     14 #include "third_party/libjingle/source/talk/app/webrtc/videosourceinterface.h"
     15 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
     16 
     17 namespace content {
     18 
     19 class CONTENT_EXPORT MediaStreamSourceExtraData
     20     : NON_EXPORTED_BASE(public blink::WebMediaStreamSource::ExtraData) {
     21  public:
     22   typedef base::Callback<void(const blink::WebMediaStreamSource& source)>
     23       SourceStopCallback;
     24 
     25   MediaStreamSourceExtraData(const StreamDeviceInfo& device_info,
     26                              const SourceStopCallback& stop_callback);
     27   MediaStreamSourceExtraData();
     28   virtual ~MediaStreamSourceExtraData();
     29 
     30   // Return device information about the camera or microphone.
     31   const StreamDeviceInfo& device_info() const {
     32     return device_info_;
     33   }
     34 
     35   void SetVideoSource(webrtc::VideoSourceInterface* source) {
     36     video_source_ = source;
     37     source_observer_.reset(new MediaStreamSourceObserver(source, this));
     38   }
     39 
     40   void SetLocalAudioSource(webrtc::AudioSourceInterface* source) {
     41     local_audio_source_ = source;
     42     // TODO(perkj): Implement a local source observer for audio.
     43     // See |source_observer_|.
     44   }
     45 
     46   void SetAudioCapturer(WebRtcAudioCapturer* capturer) {
     47     DCHECK(!audio_capturer_);
     48     audio_capturer_ = capturer;
     49   }
     50 
     51   WebRtcAudioCapturer* GetAudioCapturer() const {
     52     // TODO(perkj): |audio_capturer_| can currently be reconfigured to use
     53     // another microphone even after it has been created since only one
     54     // capturer is supported. See issue crbug/262117.
     55     // It would make more sense if a WebRtcAudioCapturer represent one and only
     56     // one audio source.
     57     if (audio_capturer_ &&
     58         device_info_.session_id == audio_capturer_->session_id()) {
     59       return audio_capturer_;
     60     }
     61     return NULL;
     62   }
     63 
     64   webrtc::VideoSourceInterface* video_source() { return video_source_.get(); }
     65   webrtc::AudioSourceInterface* local_audio_source() {
     66     return local_audio_source_.get();
     67   }
     68 
     69   void OnLocalSourceStop();
     70 
     71  private:
     72   StreamDeviceInfo device_info_;
     73 
     74   scoped_refptr<webrtc::VideoSourceInterface> video_source_;
     75 
     76   // This member holds an instance of webrtc::LocalAudioSource. This is used
     77   // as a container for audio options.
     78   // TODO(hclam): This should be merged with |audio_source_| such that it
     79   // carries audio options.
     80   scoped_refptr<webrtc::AudioSourceInterface> local_audio_source_;
     81   scoped_ptr<MediaStreamSourceObserver> source_observer_;
     82 
     83   scoped_refptr<WebRtcAudioCapturer> audio_capturer_;
     84 
     85   SourceStopCallback stop_callback_;
     86 
     87   DISALLOW_COPY_AND_ASSIGN(MediaStreamSourceExtraData);
     88 };
     89 
     90 }  // namespace content
     91 
     92 #endif  // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_EXTRA_DATA_H_
     93