OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_IMAGE_CAPTURE_FRAME_GRABBER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_EXTERNAL_MEDIA_STREAM_AUDIO_SOURCE_H_ |
6 #define CONTENT_RENDERER_MEDIA_IMAGE_CAPTURE_FRAME_GRABBER_H_ | 6 #define CONTENT_RENDERER_MEDIA_EXTERNAL_MEDIA_STREAM_AUDIO_SOURCE_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "content/renderer/media/media_stream_audio_source.h" |
9 #include "base/macros.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "base/threading/thread_checker.h" | |
12 #include "content/child/scoped_web_callbacks.h" | |
13 #include "content/common/content_export.h" | |
14 #include "content/public/renderer/media_stream_video_sink.h" | |
15 #include "third_party/WebKit/public/platform/WebImageCaptureFrameGrabber.h" | |
16 | 9 |
17 namespace blink { | 10 #include "media/base/audio_capturer_source.h" |
18 class WebMediaStreamTrack; | |
19 } | |
20 | |
21 namespace media { | |
22 class VideoFrame; | |
23 } | |
24 | 11 |
25 namespace content { | 12 namespace content { |
26 | 13 |
27 // This class grabs Video Frames from a given Media Stream Video Track, binding | 14 // Represents an externally-provided local or remote source of audio data. This |
28 // a function every time grabFrame() is called. This function receives an | 15 // allows users of the public content::MediaStreamApi to provide a |
29 // incoming VideoFrame on a background thread and converts it into the | 16 // media::AudioCapturerSource to be used as the source of audio data in the |
30 // appropriate SkBitmap which is sent back to OnSkBitmap(). This class is single | 17 // MediaStream framework. Audio data is transported directly to the tracks |
31 // threaded throughout. | 18 // (i.e., there is no audio processing). |
32 class CONTENT_EXPORT ImageCaptureFrameGrabber final | 19 class CONTENT_EXPORT ExternalMediaStreamAudioSource final |
33 : NON_EXPORTED_BASE(public blink::WebImageCaptureFrameGrabber), | 20 : NON_EXPORTED_BASE(public MediaStreamAudioSource), |
34 NON_EXPORTED_BASE(public MediaStreamVideoSink) { | 21 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) { |
35 public: | 22 public: |
36 using SkImageDeliverCB = base::Callback<void(sk_sp<SkImage>)>; | 23 ExternalMediaStreamAudioSource( |
| 24 scoped_refptr<media::AudioCapturerSource> source, |
| 25 int sample_rate, |
| 26 media::ChannelLayout channel_layout, |
| 27 int frames_per_buffer, |
| 28 bool is_remote); |
37 | 29 |
38 ImageCaptureFrameGrabber(); | 30 ~ExternalMediaStreamAudioSource() final; |
39 ~ImageCaptureFrameGrabber() override; | |
40 | |
41 // blink::WebImageCaptureFrameGrabber implementation. | |
42 void grabFrame(blink::WebMediaStreamTrack* track, | |
43 blink::WebImageCaptureGrabFrameCallbacks* callbacks) override; | |
44 | 31 |
45 private: | 32 private: |
46 void OnSkImage( | 33 // MediaStreamAudioSource implementation. |
47 ScopedWebCallbacks<blink::WebImageCaptureGrabFrameCallbacks> callbacks, | 34 bool EnsureSourceIsStarted() final; |
48 sk_sp<SkImage> image); | 35 void EnsureSourceIsStopped() final; |
49 | 36 |
| 37 // media::AudioCapturerSource::CaptureCallback implementation. |
| 38 void Capture(const media::AudioBus* audio_bus, |
| 39 int audio_delay_milliseconds, |
| 40 double volume, |
| 41 bool key_pressed) final; |
| 42 void OnCaptureError(const std::string& message) final; |
| 43 |
| 44 // The external source provided to the constructor. |
| 45 scoped_refptr<media::AudioCapturerSource> source_; |
| 46 |
| 47 // In debug builds, check that all methods that could cause object graph |
| 48 // or data flow changes are being called on the main thread. |
50 base::ThreadChecker thread_checker_; | 49 base::ThreadChecker thread_checker_; |
51 base::WeakPtrFactory<ImageCaptureFrameGrabber> weak_factory_; | |
52 | 50 |
53 DISALLOW_COPY_AND_ASSIGN(ImageCaptureFrameGrabber); | 51 // True once the source has been started successfully. |
| 52 bool was_started_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(ExternalMediaStreamAudioSource); |
54 }; | 55 }; |
55 | 56 |
56 } // namespace content | 57 } // namespace content |
57 | 58 |
58 #endif // CONTENT_RENDERER_MEDIA_IMAGE_CAPTURE_FRAME_GRABBER_H_ | 59 #endif // CONTENT_RENDERER_MEDIA_EXTERNAL_MEDIA_STREAM_AUDIO_SOURCE_H_ |
OLD | NEW |