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/video_sender/video_encoder.h" | 5 #include "media/cast/video_sender/video_encoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
11 #include "media/cast/cast_defines.h" | 11 #include "media/cast/cast_defines.h" |
12 | 12 |
13 namespace media { | 13 namespace media { |
14 namespace cast { | 14 namespace cast { |
15 | 15 |
16 void LogFrameEncodedEvent(CastEnvironment* const cast_environment, | 16 void LogFrameEncodedEvent(CastEnvironment* const cast_environment, |
17 const base::TimeTicks& capture_time) { | 17 const base::TimeTicks& capture_time) { |
18 base::TimeTicks now = cast_environment->Clock()->NowTicks(); | 18 base::TimeTicks now = cast_environment->Clock()->NowTicks(); |
19 cast_environment->Logging()->InsertFrameEvent(now, kVideoFrameEncoded, | 19 cast_environment->Logging()->InsertFrameEvent(now, kVideoFrameEncoded, |
20 GetVideoRtpTimestamp(capture_time), kFrameIdUnknown); | 20 GetVideoRtpTimestamp(capture_time), kFrameIdUnknown); |
21 } | 21 } |
22 | 22 |
23 VideoEncoder::VideoEncoder(scoped_refptr<CastEnvironment> cast_environment, | 23 VideoEncoder::VideoEncoder(scoped_refptr<CastEnvironment> cast_environment, |
24 const VideoSenderConfig& video_config, | 24 const VideoSenderConfig& video_config, |
25 uint8 max_unacked_frames) | 25 uint8 max_unacked_frames) |
26 : video_config_(video_config), | 26 : video_config_(video_config), |
27 cast_environment_(cast_environment), | 27 cast_environment_(cast_environment), |
28 skip_next_frame_(false), | 28 skip_next_frame_(false), |
29 skip_count_(0) { | 29 skip_count_(0) { |
30 if (video_config.codec == kVp8) { | 30 if (video_config.codec == transport::kVp8) { |
31 vp8_encoder_.reset(new Vp8Encoder(video_config, max_unacked_frames)); | 31 vp8_encoder_.reset(new Vp8Encoder(video_config, max_unacked_frames)); |
32 } else { | 32 } else { |
33 DCHECK(false) << "Invalid config"; // Codec not supported. | 33 DCHECK(false) << "Invalid config"; // Codec not supported. |
34 } | 34 } |
35 | 35 |
36 dynamic_config_.key_frame_requested = false; | 36 dynamic_config_.key_frame_requested = false; |
37 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; | 37 dynamic_config_.latest_frame_id_to_reference = kStartFrameId; |
38 dynamic_config_.bit_rate = video_config.start_bitrate; | 38 dynamic_config_.bit_rate = video_config.start_bitrate; |
39 } | 39 } |
40 | 40 |
41 VideoEncoder::~VideoEncoder() {} | 41 VideoEncoder::~VideoEncoder() {} |
42 | 42 |
43 bool VideoEncoder::EncodeVideoFrame( | 43 bool VideoEncoder::EncodeVideoFrame( |
44 const scoped_refptr<media::VideoFrame>& video_frame, | 44 const scoped_refptr<media::VideoFrame>& video_frame, |
45 const base::TimeTicks& capture_time, | 45 const base::TimeTicks& capture_time, |
46 const FrameEncodedCallback& frame_encoded_callback) { | 46 const FrameEncodedCallback& frame_encoded_callback) { |
47 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 47 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
48 if (video_config_.codec != kVp8) return false; | 48 if (video_config_.codec != transport::kVp8) return false; |
49 | 49 |
50 if (skip_next_frame_) { | 50 if (skip_next_frame_) { |
51 ++skip_count_; | 51 ++skip_count_; |
52 VLOG(1) << "Skip encoding frame"; | 52 VLOG(1) << "Skip encoding frame"; |
53 return false; | 53 return false; |
54 } | 54 } |
55 | 55 |
56 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 56 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
57 cast_environment_->Logging()->InsertFrameEvent(now, kVideoFrameSentToEncoder, | 57 cast_environment_->Logging()->InsertFrameEvent(now, kVideoFrameSentToEncoder, |
58 GetVideoRtpTimestamp(capture_time), kFrameIdUnknown); | 58 GetVideoRtpTimestamp(capture_time), kFrameIdUnknown); |
(...skipping 12 matching lines...) Expand all Loading... |
71 const CodecDynamicConfig& dynamic_config, | 71 const CodecDynamicConfig& dynamic_config, |
72 const FrameEncodedCallback& frame_encoded_callback) { | 72 const FrameEncodedCallback& frame_encoded_callback) { |
73 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::VIDEO_ENCODER)); | 73 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::VIDEO_ENCODER)); |
74 if (dynamic_config.key_frame_requested) { | 74 if (dynamic_config.key_frame_requested) { |
75 vp8_encoder_->GenerateKeyFrame(); | 75 vp8_encoder_->GenerateKeyFrame(); |
76 } | 76 } |
77 vp8_encoder_->LatestFrameIdToReference( | 77 vp8_encoder_->LatestFrameIdToReference( |
78 dynamic_config.latest_frame_id_to_reference); | 78 dynamic_config.latest_frame_id_to_reference); |
79 vp8_encoder_->UpdateRates(dynamic_config.bit_rate); | 79 vp8_encoder_->UpdateRates(dynamic_config.bit_rate); |
80 | 80 |
81 scoped_ptr<EncodedVideoFrame> encoded_frame(new EncodedVideoFrame()); | 81 scoped_ptr<transport::EncodedVideoFrame> encoded_frame( |
| 82 new transport::EncodedVideoFrame()); |
82 bool retval = vp8_encoder_->Encode(video_frame, encoded_frame.get()); | 83 bool retval = vp8_encoder_->Encode(video_frame, encoded_frame.get()); |
83 | 84 |
84 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 85 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
85 base::Bind(LogFrameEncodedEvent, cast_environment_, capture_time)); | 86 base::Bind(LogFrameEncodedEvent, cast_environment_, capture_time)); |
86 | 87 |
87 if (!retval) { | 88 if (!retval) { |
88 VLOG(1) << "Encoding failed"; | 89 VLOG(1) << "Encoding failed"; |
89 return; | 90 return; |
90 } | 91 } |
91 if (encoded_frame->data.size() <= 0) { | 92 if (encoded_frame->data.size() <= 0) { |
(...skipping 24 matching lines...) Expand all Loading... |
116 void VideoEncoder::LatestFrameIdToReference(uint32 frame_id) { | 117 void VideoEncoder::LatestFrameIdToReference(uint32 frame_id) { |
117 dynamic_config_.latest_frame_id_to_reference = frame_id; | 118 dynamic_config_.latest_frame_id_to_reference = frame_id; |
118 } | 119 } |
119 | 120 |
120 int VideoEncoder::NumberOfSkippedFrames() const { | 121 int VideoEncoder::NumberOfSkippedFrames() const { |
121 return skip_count_; | 122 return skip_count_; |
122 } | 123 } |
123 | 124 |
124 } // namespace cast | 125 } // namespace cast |
125 } // namespace media | 126 } // namespace media |
OLD | NEW |