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/video_sender/video_encoder_impl.h" | 5 #include "media/cast/video_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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 const VideoEncoderImpl::CodecDynamicConfig& dynamic_config, | 36 const VideoEncoderImpl::CodecDynamicConfig& dynamic_config, |
37 const VideoEncoderImpl::FrameEncodedCallback& frame_encoded_callback) { | 37 const VideoEncoderImpl::FrameEncodedCallback& frame_encoded_callback) { |
38 DCHECK(environment->CurrentlyOn(CastEnvironment::VIDEO)); | 38 DCHECK(environment->CurrentlyOn(CastEnvironment::VIDEO)); |
39 if (dynamic_config.key_frame_requested) { | 39 if (dynamic_config.key_frame_requested) { |
40 encoder->GenerateKeyFrame(); | 40 encoder->GenerateKeyFrame(); |
41 } | 41 } |
42 encoder->LatestFrameIdToReference( | 42 encoder->LatestFrameIdToReference( |
43 dynamic_config.latest_frame_id_to_reference); | 43 dynamic_config.latest_frame_id_to_reference); |
44 encoder->UpdateRates(dynamic_config.bit_rate); | 44 encoder->UpdateRates(dynamic_config.bit_rate); |
45 | 45 |
46 scoped_ptr<transport::EncodedVideoFrame> encoded_frame( | 46 scoped_ptr<transport::EncodedFrame> encoded_frame( |
47 new transport::EncodedVideoFrame()); | 47 new transport::EncodedFrame()); |
48 bool retval = encoder->Encode(video_frame, encoded_frame.get()); | 48 if (!encoder->Encode(video_frame, encoded_frame.get())) { |
49 | |
50 encoded_frame->rtp_timestamp = transport::GetVideoRtpTimestamp(capture_time); | |
51 | |
52 if (!retval) { | |
53 VLOG(1) << "Encoding failed"; | 49 VLOG(1) << "Encoding failed"; |
54 return; | 50 return; |
55 } | 51 } |
56 if (encoded_frame->data.size() <= 0) { | 52 if (encoded_frame->data.empty()) { |
57 VLOG(1) << "Encoding resulted in an empty frame"; | 53 VLOG(1) << "Encoding resulted in an empty frame"; |
58 return; | 54 return; |
59 } | 55 } |
| 56 encoded_frame->rtp_timestamp = transport::GetVideoRtpTimestamp(capture_time); |
| 57 encoded_frame->reference_time = capture_time; |
| 58 |
60 environment->PostTask( | 59 environment->PostTask( |
61 CastEnvironment::MAIN, | 60 CastEnvironment::MAIN, |
62 FROM_HERE, | 61 FROM_HERE, |
63 base::Bind( | 62 base::Bind( |
64 frame_encoded_callback, base::Passed(&encoded_frame), capture_time)); | 63 frame_encoded_callback, base::Passed(&encoded_frame))); |
65 } | 64 } |
66 } // namespace | 65 } // namespace |
67 | 66 |
68 VideoEncoderImpl::VideoEncoderImpl( | 67 VideoEncoderImpl::VideoEncoderImpl( |
69 scoped_refptr<CastEnvironment> cast_environment, | 68 scoped_refptr<CastEnvironment> cast_environment, |
70 const VideoSenderConfig& video_config, | 69 const VideoSenderConfig& video_config, |
71 uint8 max_unacked_frames) | 70 uint8 max_unacked_frames) |
72 : video_config_(video_config), | 71 : video_config_(video_config), |
73 cast_environment_(cast_environment), | 72 cast_environment_(cast_environment), |
74 skip_next_frame_(false), | 73 skip_next_frame_(false), |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 144 |
146 // Inform the encoder to only reference frames older or equal to frame_id; | 145 // Inform the encoder to only reference frames older or equal to frame_id; |
147 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { | 146 void VideoEncoderImpl::LatestFrameIdToReference(uint32 frame_id) { |
148 dynamic_config_.latest_frame_id_to_reference = frame_id; | 147 dynamic_config_.latest_frame_id_to_reference = frame_id; |
149 } | 148 } |
150 | 149 |
151 int VideoEncoderImpl::NumberOfSkippedFrames() const { return skip_count_; } | 150 int VideoEncoderImpl::NumberOfSkippedFrames() const { return skip_count_; } |
152 | 151 |
153 } // namespace cast | 152 } // namespace cast |
154 } // namespace media | 153 } // namespace media |
OLD | NEW |