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 "content/renderer/media/rtc_video_decoder_bridge_tv.h" | 5 #include "content/renderer/media/rtc_video_decoder_bridge_tv.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
15 #include "base/message_loop/message_loop_proxy.h" | 15 #include "base/message_loop/message_loop_proxy.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "content/renderer/media/rtc_video_decoder_factory_tv.h" | 17 #include "content/renderer/media/rtc_video_decoder_factory_tv.h" |
18 #include "media/base/bind_to_loop.h" | 18 #include "media/base/bind_to_loop.h" |
19 #include "media/base/decoder_buffer.h" | 19 #include "media/base/decoder_buffer.h" |
20 #include "third_party/libjingle/source/talk/base/ratetracker.h" | 20 #include "third_party/libjingle/source/talk/base/ratetracker.h" |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
24 RTCVideoDecoderBridgeTv::RTCVideoDecoderBridgeTv( | 24 RTCVideoDecoderBridgeTv::RTCVideoDecoderBridgeTv( |
25 RTCVideoDecoderFactoryTv* factory) | 25 RTCVideoDecoderFactoryTv* factory) |
26 : factory_(factory), | 26 : factory_(factory), |
27 is_initialized_(false), | 27 is_initialized_(false), |
28 first_frame_(true), | 28 first_frame_(true) {} |
29 decode_complete_callback_(NULL) {} | |
30 | 29 |
31 RTCVideoDecoderBridgeTv::~RTCVideoDecoderBridgeTv() {} | 30 RTCVideoDecoderBridgeTv::~RTCVideoDecoderBridgeTv() {} |
32 | 31 |
33 int32_t RTCVideoDecoderBridgeTv::InitDecode( | 32 int32_t RTCVideoDecoderBridgeTv::InitDecode( |
34 const webrtc::VideoCodec* codec_settings, | 33 const webrtc::VideoCodec* codec_settings, |
35 int32_t number_of_cores) { | 34 int32_t number_of_cores) { |
36 // We don't support non-VP8 codec, feedback mode, nor double-initialization | 35 // We don't support non-VP8 codec, feedback mode, nor double-initialization |
37 if (codec_settings->codecType != webrtc::kVideoCodecVP8 || | 36 if (codec_settings->codecType != webrtc::kVideoCodecVP8 || |
38 codec_settings->codecSpecific.VP8.feedbackModeOn || is_initialized_) | 37 codec_settings->codecSpecific.VP8.feedbackModeOn || is_initialized_) |
39 return WEBRTC_VIDEO_CODEC_ERROR; | 38 return WEBRTC_VIDEO_CODEC_ERROR; |
(...skipping 10 matching lines...) Expand all Loading... |
50 const webrtc::EncodedImage& input_image, | 49 const webrtc::EncodedImage& input_image, |
51 bool missing_frames, | 50 bool missing_frames, |
52 const webrtc::RTPFragmentationHeader* fragmentation, | 51 const webrtc::RTPFragmentationHeader* fragmentation, |
53 const webrtc::CodecSpecificInfo* codec_specific_info, | 52 const webrtc::CodecSpecificInfo* codec_specific_info, |
54 int64_t render_time_ms) { | 53 int64_t render_time_ms) { |
55 // Unlike the SW decoder in libvpx, hw decoder can not handle broken frames. | 54 // Unlike the SW decoder in libvpx, hw decoder can not handle broken frames. |
56 // Here, we return an error in order to request a key frame. | 55 // Here, we return an error in order to request a key frame. |
57 if (missing_frames || !input_image._completeFrame) | 56 if (missing_frames || !input_image._completeFrame) |
58 return WEBRTC_VIDEO_CODEC_ERROR; | 57 return WEBRTC_VIDEO_CODEC_ERROR; |
59 | 58 |
60 if (!is_initialized_ || decode_complete_callback_ == NULL) | 59 if (!is_initialized_) |
61 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 60 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
62 | 61 |
63 if (first_frame_) { | 62 if (first_frame_) { |
64 // If the first frame is not a key frame, return an error to request a key | 63 // If the first frame is not a key frame, return an error to request a key |
65 // frame. | 64 // frame. |
66 if (input_image._frameType != webrtc::kKeyFrame) | 65 if (input_image._frameType != webrtc::kKeyFrame) |
67 return WEBRTC_VIDEO_CODEC_ERROR; | 66 return WEBRTC_VIDEO_CODEC_ERROR; |
68 | 67 |
69 // Google TV expects timestamp from 0, so we store the initial timestamp as | 68 // Google TV expects timestamp from 0, so we store the initial timestamp as |
70 // an offset and subtract the value from every timestamps to meet the | 69 // an offset and subtract the value from every timestamps to meet the |
(...skipping 13 matching lines...) Expand all Loading... |
84 } | 83 } |
85 // |input_image_| may be destroyed after this call, so we make a copy of the | 84 // |input_image_| may be destroyed after this call, so we make a copy of the |
86 // buffer so that we can queue the buffer asynchronously. | 85 // buffer so that we can queue the buffer asynchronously. |
87 scoped_refptr<media::DecoderBuffer> buffer = | 86 scoped_refptr<media::DecoderBuffer> buffer = |
88 media::DecoderBuffer::CopyFrom(input_image._buffer, input_image._length); | 87 media::DecoderBuffer::CopyFrom(input_image._buffer, input_image._length); |
89 if (render_time_ms != -1) { | 88 if (render_time_ms != -1) { |
90 buffer->set_timestamp(base::TimeDelta::FromMilliseconds( | 89 buffer->set_timestamp(base::TimeDelta::FromMilliseconds( |
91 render_time_ms - timestamp_offset_millis_)); | 90 render_time_ms - timestamp_offset_millis_)); |
92 } | 91 } |
93 | 92 |
94 factory_->QueueBuffer( | 93 factory_->QueueBuffer(buffer, new_size); |
95 buffer, | |
96 base::Bind(&RTCVideoDecoderBridgeTv::RunDecodeCompleteCallback, | |
97 decode_complete_callback_, | |
98 input_image._timeStamp, | |
99 size_), | |
100 new_size); | |
101 | 94 |
102 return WEBRTC_VIDEO_CODEC_OK; | 95 return WEBRTC_VIDEO_CODEC_OK; |
103 } | 96 } |
104 | 97 |
105 int32_t RTCVideoDecoderBridgeTv::RegisterDecodeCompleteCallback( | 98 int32_t RTCVideoDecoderBridgeTv::RegisterDecodeCompleteCallback( |
106 webrtc::DecodedImageCallback* callback) { | 99 webrtc::DecodedImageCallback* callback) { |
107 decode_complete_callback_ = callback; | |
108 return WEBRTC_VIDEO_CODEC_OK; | 100 return WEBRTC_VIDEO_CODEC_OK; |
109 } | 101 } |
110 | 102 |
111 int32_t RTCVideoDecoderBridgeTv::Release() { | 103 int32_t RTCVideoDecoderBridgeTv::Release() { |
112 is_initialized_ = false; | 104 is_initialized_ = false; |
113 return WEBRTC_VIDEO_CODEC_OK; | 105 return WEBRTC_VIDEO_CODEC_OK; |
114 } | 106 } |
115 | 107 |
116 int32_t RTCVideoDecoderBridgeTv::Reset() { | 108 int32_t RTCVideoDecoderBridgeTv::Reset() { |
117 first_frame_ = true; | 109 first_frame_ = true; |
118 return WEBRTC_VIDEO_CODEC_OK; | 110 return WEBRTC_VIDEO_CODEC_OK; |
119 } | 111 } |
120 | 112 |
121 // static | |
122 void RTCVideoDecoderBridgeTv::RunDecodeCompleteCallback( | |
123 webrtc::DecodedImageCallback* callback, | |
124 int64_t timestamp, | |
125 gfx::Size size) { | |
126 // We call the decode complete callback function to notify libjingle that | |
127 // decoding is finished. In addition, this also reports back to libjingle that | |
128 // the particular video frame with |timestamp| is correctly rendered to | |
129 // libjingle, so that it can generate proper stats. | |
130 webrtc::I420VideoFrame dummy_video_frame; | |
131 int half_width = (size.width() + 1) / 2; | |
132 dummy_video_frame.CreateEmptyFrame( | |
133 size.width(), size.height(), size.width(), half_width, half_width); | |
134 dummy_video_frame.set_timestamp(timestamp); | |
135 callback->Decoded(dummy_video_frame); | |
136 } | |
137 | |
138 } // namespace content | 113 } // namespace content |
OLD | NEW |