OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 * | 9 * |
10 */ | 10 */ |
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 // In practice libvpx keeps a few (~3-4) buffers alive at a time. | 925 // In practice libvpx keeps a few (~3-4) buffers alive at a time. |
926 if (vpx_codec_decode(decoder_, buffer, | 926 if (vpx_codec_decode(decoder_, buffer, |
927 static_cast<unsigned int>(input_image._length), 0, | 927 static_cast<unsigned int>(input_image._length), 0, |
928 VPX_DL_REALTIME)) { | 928 VPX_DL_REALTIME)) { |
929 return WEBRTC_VIDEO_CODEC_ERROR; | 929 return WEBRTC_VIDEO_CODEC_ERROR; |
930 } | 930 } |
931 // |img->fb_priv| contains the image data, a reference counted Vp9FrameBuffer. | 931 // |img->fb_priv| contains the image data, a reference counted Vp9FrameBuffer. |
932 // It may be released by libvpx during future vpx_codec_decode or | 932 // It may be released by libvpx during future vpx_codec_decode or |
933 // vpx_codec_destroy calls. | 933 // vpx_codec_destroy calls. |
934 img = vpx_codec_get_frame(decoder_, &iter); | 934 img = vpx_codec_get_frame(decoder_, &iter); |
935 int ret = ReturnFrame(img, input_image._timeStamp, input_image.ntp_time_ms_); | 935 int qp; |
| 936 vpx_codec_err_t vpx_ret = |
| 937 vpx_codec_control(decoder_, VPXD_GET_LAST_QUANTIZER, &qp); |
| 938 RTC_DCHECK_EQ(vpx_ret, VPX_CODEC_OK); |
| 939 int ret = |
| 940 ReturnFrame(img, input_image._timeStamp, input_image.ntp_time_ms_, qp); |
936 if (ret != 0) { | 941 if (ret != 0) { |
937 return ret; | 942 return ret; |
938 } | 943 } |
939 return WEBRTC_VIDEO_CODEC_OK; | 944 return WEBRTC_VIDEO_CODEC_OK; |
940 } | 945 } |
941 | 946 |
942 int VP9DecoderImpl::ReturnFrame(const vpx_image_t* img, | 947 int VP9DecoderImpl::ReturnFrame(const vpx_image_t* img, |
943 uint32_t timestamp, | 948 uint32_t timestamp, |
944 int64_t ntp_time_ms) { | 949 int64_t ntp_time_ms, |
| 950 int qp) { |
945 if (img == NULL) { | 951 if (img == NULL) { |
946 // Decoder OK and NULL image => No show frame. | 952 // Decoder OK and NULL image => No show frame. |
947 return WEBRTC_VIDEO_CODEC_NO_OUTPUT; | 953 return WEBRTC_VIDEO_CODEC_NO_OUTPUT; |
948 } | 954 } |
949 | 955 |
950 // This buffer contains all of |img|'s image data, a reference counted | 956 // This buffer contains all of |img|'s image data, a reference counted |
951 // Vp9FrameBuffer. (libvpx is done with the buffers after a few | 957 // Vp9FrameBuffer. (libvpx is done with the buffers after a few |
952 // vpx_codec_decode calls or vpx_codec_destroy). | 958 // vpx_codec_decode calls or vpx_codec_destroy). |
953 Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer = | 959 Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer = |
954 static_cast<Vp9FrameBufferPool::Vp9FrameBuffer*>(img->fb_priv); | 960 static_cast<Vp9FrameBufferPool::Vp9FrameBuffer*>(img->fb_priv); |
955 // The buffer can be used directly by the VideoFrame (without copy) by | 961 // The buffer can be used directly by the VideoFrame (without copy) by |
956 // using a WrappedI420Buffer. | 962 // using a WrappedI420Buffer. |
957 rtc::scoped_refptr<WrappedI420Buffer> img_wrapped_buffer( | 963 rtc::scoped_refptr<WrappedI420Buffer> img_wrapped_buffer( |
958 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( | 964 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( |
959 img->d_w, img->d_h, img->planes[VPX_PLANE_Y], | 965 img->d_w, img->d_h, img->planes[VPX_PLANE_Y], |
960 img->stride[VPX_PLANE_Y], img->planes[VPX_PLANE_U], | 966 img->stride[VPX_PLANE_Y], img->planes[VPX_PLANE_U], |
961 img->stride[VPX_PLANE_U], img->planes[VPX_PLANE_V], | 967 img->stride[VPX_PLANE_U], img->planes[VPX_PLANE_V], |
962 img->stride[VPX_PLANE_V], | 968 img->stride[VPX_PLANE_V], |
963 // WrappedI420Buffer's mechanism for allowing the release of its frame | 969 // WrappedI420Buffer's mechanism for allowing the release of its frame |
964 // buffer is through a callback function. This is where we should | 970 // buffer is through a callback function. This is where we should |
965 // release |img_buffer|. | 971 // release |img_buffer|. |
966 rtc::KeepRefUntilDone(img_buffer))); | 972 rtc::KeepRefUntilDone(img_buffer))); |
967 | 973 |
968 VideoFrame decoded_image(img_wrapped_buffer, timestamp, | 974 VideoFrame decoded_image(img_wrapped_buffer, timestamp, |
969 0 /* render_time_ms */, webrtc::kVideoRotation_0); | 975 0 /* render_time_ms */, webrtc::kVideoRotation_0); |
970 decoded_image.set_ntp_time_ms(ntp_time_ms); | 976 decoded_image.set_ntp_time_ms(ntp_time_ms); |
971 | 977 |
972 int ret = decode_complete_callback_->Decoded(decoded_image); | 978 decode_complete_callback_->Decoded(decoded_image, rtc::Optional<int32_t>(), |
973 if (ret != 0) | 979 rtc::Optional<uint8_t>(qp)); |
974 return ret; | |
975 return WEBRTC_VIDEO_CODEC_OK; | 980 return WEBRTC_VIDEO_CODEC_OK; |
976 } | 981 } |
977 | 982 |
978 int VP9DecoderImpl::RegisterDecodeCompleteCallback( | 983 int VP9DecoderImpl::RegisterDecodeCompleteCallback( |
979 DecodedImageCallback* callback) { | 984 DecodedImageCallback* callback) { |
980 decode_complete_callback_ = callback; | 985 decode_complete_callback_ = callback; |
981 return WEBRTC_VIDEO_CODEC_OK; | 986 return WEBRTC_VIDEO_CODEC_OK; |
982 } | 987 } |
983 | 988 |
984 int VP9DecoderImpl::Release() { | 989 int VP9DecoderImpl::Release() { |
(...skipping 12 matching lines...) Expand all Loading... |
997 frame_buffer_pool_.ClearPool(); | 1002 frame_buffer_pool_.ClearPool(); |
998 inited_ = false; | 1003 inited_ = false; |
999 return WEBRTC_VIDEO_CODEC_OK; | 1004 return WEBRTC_VIDEO_CODEC_OK; |
1000 } | 1005 } |
1001 | 1006 |
1002 const char* VP9DecoderImpl::ImplementationName() const { | 1007 const char* VP9DecoderImpl::ImplementationName() const { |
1003 return "libvpx"; | 1008 return "libvpx"; |
1004 } | 1009 } |
1005 | 1010 |
1006 } // namespace webrtc | 1011 } // namespace webrtc |
OLD | NEW |