OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sender/video_encoder_impl.h" | 5 #include "media/cast/sender/video_encoder_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
13 #include "media/cast/cast_defines.h" | 13 #include "media/cast/cast_defines.h" |
14 #include "media/cast/sender/fake_software_video_encoder.h" | 14 #include "media/cast/sender/fake_software_video_encoder.h" |
| 15 #if !defined(MEDIA_DISABLE_LIBVPX) |
15 #include "media/cast/sender/vp8_encoder.h" | 16 #include "media/cast/sender/vp8_encoder.h" |
| 17 #endif // !defined(MEDIA_DISABLE_LIBVPX) |
16 | 18 |
17 namespace media { | 19 namespace media { |
18 namespace cast { | 20 namespace cast { |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
| 24 #if !defined(MEDIA_DISABLE_LIBVPX) |
22 typedef base::Callback<void(Vp8Encoder*)> PassEncoderCallback; | 25 typedef base::Callback<void(Vp8Encoder*)> PassEncoderCallback; |
23 | 26 |
24 void InitializeEncoderOnEncoderThread( | 27 void InitializeEncoderOnEncoderThread( |
25 const scoped_refptr<CastEnvironment>& environment, | 28 const scoped_refptr<CastEnvironment>& environment, |
26 SoftwareVideoEncoder* encoder) { | 29 SoftwareVideoEncoder* encoder) { |
27 DCHECK(environment->CurrentlyOn(CastEnvironment::VIDEO)); | 30 DCHECK(environment->CurrentlyOn(CastEnvironment::VIDEO)); |
28 encoder->Initialize(); | 31 encoder->Initialize(); |
29 } | 32 } |
| 33 #endif // !defined(MEDIA_DISABLE_LIBVPX) |
30 | 34 |
31 void EncodeVideoFrameOnEncoderThread( | 35 void EncodeVideoFrameOnEncoderThread( |
32 scoped_refptr<CastEnvironment> environment, | 36 scoped_refptr<CastEnvironment> environment, |
33 SoftwareVideoEncoder* encoder, | 37 SoftwareVideoEncoder* encoder, |
34 const scoped_refptr<media::VideoFrame>& video_frame, | 38 const scoped_refptr<media::VideoFrame>& video_frame, |
35 const base::TimeTicks& capture_time, | 39 const base::TimeTicks& capture_time, |
36 const VideoEncoderImpl::CodecDynamicConfig& dynamic_config, | 40 const VideoEncoderImpl::CodecDynamicConfig& dynamic_config, |
37 const VideoEncoderImpl::FrameEncodedCallback& frame_encoded_callback) { | 41 const VideoEncoderImpl::FrameEncodedCallback& frame_encoded_callback) { |
38 DCHECK(environment->CurrentlyOn(CastEnvironment::VIDEO)); | 42 DCHECK(environment->CurrentlyOn(CastEnvironment::VIDEO)); |
39 if (dynamic_config.key_frame_requested) { | 43 if (dynamic_config.key_frame_requested) { |
(...skipping 23 matching lines...) Expand all Loading... |
63 frame_encoded_callback, base::Passed(&encoded_frame))); | 67 frame_encoded_callback, base::Passed(&encoded_frame))); |
64 } | 68 } |
65 } // namespace | 69 } // namespace |
66 | 70 |
67 VideoEncoderImpl::VideoEncoderImpl( | 71 VideoEncoderImpl::VideoEncoderImpl( |
68 scoped_refptr<CastEnvironment> cast_environment, | 72 scoped_refptr<CastEnvironment> cast_environment, |
69 const VideoSenderConfig& video_config, | 73 const VideoSenderConfig& video_config, |
70 int max_unacked_frames) | 74 int max_unacked_frames) |
71 : cast_environment_(cast_environment) { | 75 : cast_environment_(cast_environment) { |
72 if (video_config.codec == CODEC_VIDEO_VP8) { | 76 if (video_config.codec == CODEC_VIDEO_VP8) { |
| 77 #if !defined(MEDIA_DISABLE_LIBVPX) |
73 encoder_.reset(new Vp8Encoder(video_config, max_unacked_frames)); | 78 encoder_.reset(new Vp8Encoder(video_config, max_unacked_frames)); |
74 cast_environment_->PostTask(CastEnvironment::VIDEO, | 79 cast_environment_->PostTask(CastEnvironment::VIDEO, |
75 FROM_HERE, | 80 FROM_HERE, |
76 base::Bind(&InitializeEncoderOnEncoderThread, | 81 base::Bind(&InitializeEncoderOnEncoderThread, |
77 cast_environment, | 82 cast_environment, |
78 encoder_.get())); | 83 encoder_.get())); |
| 84 #endif // !defined(MEDIA_DISABLE_LIBVPX) |
79 #ifndef OFFICIAL_BUILD | 85 #ifndef OFFICIAL_BUILD |
80 } else if (video_config.codec == CODEC_VIDEO_FAKE) { | 86 } else if (video_config.codec == CODEC_VIDEO_FAKE) { |
81 encoder_.reset(new FakeSoftwareVideoEncoder(video_config)); | 87 encoder_.reset(new FakeSoftwareVideoEncoder(video_config)); |
82 #endif | 88 #endif |
83 } else { | 89 } else { |
84 DCHECK(false) << "Invalid config"; // Codec not supported. | 90 DCHECK(false) << "Invalid config"; // Codec not supported. |
85 } | 91 } |
86 | 92 |
87 dynamic_config_.key_frame_requested = false; | 93 dynamic_config_.key_frame_requested = false; |
88 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; | 94 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 dynamic_config_.key_frame_requested = true; | 135 dynamic_config_.key_frame_requested = true; |
130 } | 136 } |
131 | 137 |
132 // Inform the encoder to only reference frames older or equal to frame_id; | 138 // Inform the encoder to only reference frames older or equal to frame_id; |
133 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { | 139 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { |
134 dynamic_config_.latest_frame_id_to_reference = frame_id; | 140 dynamic_config_.latest_frame_id_to_reference = frame_id; |
135 } | 141 } |
136 | 142 |
137 } // namespace cast | 143 } // namespace cast |
138 } // namespace media | 144 } // namespace media |
OLD | NEW |