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 #include "media/cast/sender/video_frame_factory.h" |
12 | 13 |
13 namespace media { | 14 namespace media { |
14 namespace cast { | 15 namespace cast { |
15 | 16 |
16 // The LocalVideoFrameInput class posts all incoming video frames to the main | 17 // The LocalVideoFrameInput class posts all incoming video frames to the main |
17 // cast thread for processing. | 18 // cast thread for processing. |
18 class LocalVideoFrameInput : public VideoFrameInput { | 19 class LocalVideoFrameInput : public VideoFrameInput { |
19 public: | 20 public: |
20 LocalVideoFrameInput(scoped_refptr<CastEnvironment> cast_environment, | 21 LocalVideoFrameInput(scoped_refptr<CastEnvironment> cast_environment, |
21 base::WeakPtr<VideoSender> video_sender) | 22 base::WeakPtr<VideoSender> video_sender, |
22 : cast_environment_(cast_environment), video_sender_(video_sender) {} | 23 scoped_ptr<VideoFrameFactory> video_frame_factory) |
| 24 : cast_environment_(cast_environment), |
| 25 video_sender_(video_sender), |
| 26 video_frame_factory_(video_frame_factory.Pass()) {} |
23 | 27 |
24 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, | 28 void InsertRawVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, |
25 const base::TimeTicks& capture_time) override { | 29 const base::TimeTicks& capture_time) override { |
26 cast_environment_->PostTask(CastEnvironment::MAIN, | 30 cast_environment_->PostTask(CastEnvironment::MAIN, |
27 FROM_HERE, | 31 FROM_HERE, |
28 base::Bind(&VideoSender::InsertRawVideoFrame, | 32 base::Bind(&VideoSender::InsertRawVideoFrame, |
29 video_sender_, | 33 video_sender_, |
30 video_frame, | 34 video_frame, |
31 capture_time)); | 35 capture_time)); |
32 } | 36 } |
33 | 37 |
| 38 scoped_refptr<VideoFrame> CreateOptimizedFrame( |
| 39 base::TimeDelta timestamp) override { |
| 40 DCHECK(video_frame_factory_.get()); |
| 41 return video_frame_factory_->CreateFrame(timestamp); |
| 42 } |
| 43 |
| 44 bool SupportsCreateOptimizedFrame() const override { |
| 45 return video_frame_factory_.get() != nullptr; |
| 46 } |
| 47 |
34 protected: | 48 protected: |
35 ~LocalVideoFrameInput() override {} | 49 ~LocalVideoFrameInput() override {} |
36 | 50 |
37 private: | 51 private: |
38 friend class base::RefCountedThreadSafe<LocalVideoFrameInput>; | 52 friend class base::RefCountedThreadSafe<LocalVideoFrameInput>; |
39 | 53 |
40 scoped_refptr<CastEnvironment> cast_environment_; | 54 scoped_refptr<CastEnvironment> cast_environment_; |
41 base::WeakPtr<VideoSender> video_sender_; | 55 base::WeakPtr<VideoSender> video_sender_; |
| 56 scoped_ptr<VideoFrameFactory> video_frame_factory_; |
42 | 57 |
43 DISALLOW_COPY_AND_ASSIGN(LocalVideoFrameInput); | 58 DISALLOW_COPY_AND_ASSIGN(LocalVideoFrameInput); |
44 }; | 59 }; |
45 | 60 |
46 // The LocalAudioFrameInput class posts all incoming audio frames to the main | 61 // The LocalAudioFrameInput class posts all incoming audio frames to the main |
47 // cast thread for processing. Therefore frames can be inserted from any thread. | 62 // cast thread for processing. Therefore frames can be inserted from any thread. |
48 class LocalAudioFrameInput : public AudioFrameInput { | 63 class LocalAudioFrameInput : public AudioFrameInput { |
49 public: | 64 public: |
50 LocalAudioFrameInput(scoped_refptr<CastEnvironment> cast_environment, | 65 LocalAudioFrameInput(scoped_refptr<CastEnvironment> cast_environment, |
51 base::WeakPtr<AudioSender> audio_sender) | 66 base::WeakPtr<AudioSender> audio_sender) |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 177 } |
163 if (video_sender_) { | 178 if (video_sender_) { |
164 video_sender_->SetTargetPlayoutDelay(new_target_playout_delay); | 179 video_sender_->SetTargetPlayoutDelay(new_target_playout_delay); |
165 } | 180 } |
166 } | 181 } |
167 | 182 |
168 void CastSenderImpl::OnVideoInitialized( | 183 void CastSenderImpl::OnVideoInitialized( |
169 const CastInitializationCallback& initialization_cb, | 184 const CastInitializationCallback& initialization_cb, |
170 media::cast::CastInitializationStatus result) { | 185 media::cast::CastInitializationStatus result) { |
171 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 186 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
172 video_frame_input_ = | 187 if (result == STATUS_VIDEO_INITIALIZED) { |
173 new LocalVideoFrameInput(cast_environment_, video_sender_->AsWeakPtr()); | 188 video_frame_input_ = |
| 189 new LocalVideoFrameInput(cast_environment_, video_sender_->AsWeakPtr(), |
| 190 video_sender_->CreateVideoFrameFactory()); |
| 191 } |
174 initialization_cb.Run(result); | 192 initialization_cb.Run(result); |
175 } | 193 } |
176 | 194 |
177 } // namespace cast | 195 } // namespace cast |
178 } // namespace media | 196 } // namespace media |
OLD | NEW |