| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "media/cast/cast_sender_impl.h" | 5 #include "media/cast/cast_sender_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 namespace cast { | 14 namespace cast { |
| 15 | 15 |
| 16 // The LocalVideoFrameInput class posts all incoming video frames to the main | 16 // The LocalVideoFrameInput class posts all incoming video frames to the main |
| 17 // cast thread for processing. | 17 // cast thread for processing. |
| 18 class LocalVideoFrameInput : public VideoFrameInput { | 18 class LocalVideoFrameInput : public VideoFrameInput { |
| 19 public: | 19 public: |
| 20 LocalVideoFrameInput(scoped_refptr<CastEnvironment> cast_environment, | 20 LocalVideoFrameInput(scoped_refptr<CastEnvironment> cast_environment, |
| 21 base::WeakPtr<VideoSender> video_sender) | 21 base::WeakPtr<VideoSender> video_sender) |
| 22 : cast_environment_(cast_environment), video_sender_(video_sender) {} | 22 : cast_environment_(cast_environment), video_sender_(video_sender) {} |
| 23 | 23 |
| 24 virtual void InsertRawVideoFrame( | 24 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, |
| 25 const scoped_refptr<media::VideoFrame>& video_frame, | 25 const base::TimeTicks& capture_time) override { |
| 26 const base::TimeTicks& capture_time) override { | |
| 27 cast_environment_->PostTask(CastEnvironment::MAIN, | 26 cast_environment_->PostTask(CastEnvironment::MAIN, |
| 28 FROM_HERE, | 27 FROM_HERE, |
| 29 base::Bind(&VideoSender::InsertRawVideoFrame, | 28 base::Bind(&VideoSender::InsertRawVideoFrame, |
| 30 video_sender_, | 29 video_sender_, |
| 31 video_frame, | 30 video_frame, |
| 32 capture_time)); | 31 capture_time)); |
| 33 } | 32 } |
| 34 | 33 |
| 35 protected: | 34 protected: |
| 36 virtual ~LocalVideoFrameInput() {} | 35 ~LocalVideoFrameInput() override {} |
| 37 | 36 |
| 38 private: | 37 private: |
| 39 friend class base::RefCountedThreadSafe<LocalVideoFrameInput>; | 38 friend class base::RefCountedThreadSafe<LocalVideoFrameInput>; |
| 40 | 39 |
| 41 scoped_refptr<CastEnvironment> cast_environment_; | 40 scoped_refptr<CastEnvironment> cast_environment_; |
| 42 base::WeakPtr<VideoSender> video_sender_; | 41 base::WeakPtr<VideoSender> video_sender_; |
| 43 | 42 |
| 44 DISALLOW_COPY_AND_ASSIGN(LocalVideoFrameInput); | 43 DISALLOW_COPY_AND_ASSIGN(LocalVideoFrameInput); |
| 45 }; | 44 }; |
| 46 | 45 |
| 47 // The LocalAudioFrameInput class posts all incoming audio frames to the main | 46 // The LocalAudioFrameInput class posts all incoming audio frames to the main |
| 48 // cast thread for processing. Therefore frames can be inserted from any thread. | 47 // cast thread for processing. Therefore frames can be inserted from any thread. |
| 49 class LocalAudioFrameInput : public AudioFrameInput { | 48 class LocalAudioFrameInput : public AudioFrameInput { |
| 50 public: | 49 public: |
| 51 LocalAudioFrameInput(scoped_refptr<CastEnvironment> cast_environment, | 50 LocalAudioFrameInput(scoped_refptr<CastEnvironment> cast_environment, |
| 52 base::WeakPtr<AudioSender> audio_sender) | 51 base::WeakPtr<AudioSender> audio_sender) |
| 53 : cast_environment_(cast_environment), audio_sender_(audio_sender) {} | 52 : cast_environment_(cast_environment), audio_sender_(audio_sender) {} |
| 54 | 53 |
| 55 virtual void InsertAudio(scoped_ptr<AudioBus> audio_bus, | 54 void InsertAudio(scoped_ptr<AudioBus> audio_bus, |
| 56 const base::TimeTicks& recorded_time) override { | 55 const base::TimeTicks& recorded_time) override { |
| 57 cast_environment_->PostTask(CastEnvironment::MAIN, | 56 cast_environment_->PostTask(CastEnvironment::MAIN, |
| 58 FROM_HERE, | 57 FROM_HERE, |
| 59 base::Bind(&AudioSender::InsertAudio, | 58 base::Bind(&AudioSender::InsertAudio, |
| 60 audio_sender_, | 59 audio_sender_, |
| 61 base::Passed(&audio_bus), | 60 base::Passed(&audio_bus), |
| 62 recorded_time)); | 61 recorded_time)); |
| 63 } | 62 } |
| 64 | 63 |
| 65 protected: | 64 protected: |
| 66 virtual ~LocalAudioFrameInput() {} | 65 ~LocalAudioFrameInput() override {} |
| 67 | 66 |
| 68 private: | 67 private: |
| 69 friend class base::RefCountedThreadSafe<LocalAudioFrameInput>; | 68 friend class base::RefCountedThreadSafe<LocalAudioFrameInput>; |
| 70 | 69 |
| 71 scoped_refptr<CastEnvironment> cast_environment_; | 70 scoped_refptr<CastEnvironment> cast_environment_; |
| 72 base::WeakPtr<AudioSender> audio_sender_; | 71 base::WeakPtr<AudioSender> audio_sender_; |
| 73 | 72 |
| 74 DISALLOW_COPY_AND_ASSIGN(LocalAudioFrameInput); | 73 DISALLOW_COPY_AND_ASSIGN(LocalAudioFrameInput); |
| 75 }; | 74 }; |
| 76 | 75 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 const CastInitializationCallback& initialization_cb, | 169 const CastInitializationCallback& initialization_cb, |
| 171 media::cast::CastInitializationStatus result) { | 170 media::cast::CastInitializationStatus result) { |
| 172 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 171 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 173 video_frame_input_ = | 172 video_frame_input_ = |
| 174 new LocalVideoFrameInput(cast_environment_, video_sender_->AsWeakPtr()); | 173 new LocalVideoFrameInput(cast_environment_, video_sender_->AsWeakPtr()); |
| 175 initialization_cb.Run(result); | 174 initialization_cb.Run(result); |
| 176 } | 175 } |
| 177 | 176 |
| 178 } // namespace cast | 177 } // namespace cast |
| 179 } // namespace media | 178 } // namespace media |
| OLD | NEW |