| 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 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 // In practice libvpx keeps a few (~3-4) buffers alive at a time. | 906 // In practice libvpx keeps a few (~3-4) buffers alive at a time. |
| 907 if (vpx_codec_decode(decoder_, buffer, | 907 if (vpx_codec_decode(decoder_, buffer, |
| 908 static_cast<unsigned int>(input_image._length), 0, | 908 static_cast<unsigned int>(input_image._length), 0, |
| 909 VPX_DL_REALTIME)) { | 909 VPX_DL_REALTIME)) { |
| 910 return WEBRTC_VIDEO_CODEC_ERROR; | 910 return WEBRTC_VIDEO_CODEC_ERROR; |
| 911 } | 911 } |
| 912 // |img->fb_priv| contains the image data, a reference counted Vp9FrameBuffer. | 912 // |img->fb_priv| contains the image data, a reference counted Vp9FrameBuffer. |
| 913 // It may be released by libvpx during future vpx_codec_decode or | 913 // It may be released by libvpx during future vpx_codec_decode or |
| 914 // vpx_codec_destroy calls. | 914 // vpx_codec_destroy calls. |
| 915 img = vpx_codec_get_frame(decoder_, &iter); | 915 img = vpx_codec_get_frame(decoder_, &iter); |
| 916 int ret = ReturnFrame(img, input_image._timeStamp); | 916 int ret = ReturnFrame(img, input_image._timeStamp, input_image.ntp_time_ms_); |
| 917 if (ret != 0) { | 917 if (ret != 0) { |
| 918 return ret; | 918 return ret; |
| 919 } | 919 } |
| 920 return WEBRTC_VIDEO_CODEC_OK; | 920 return WEBRTC_VIDEO_CODEC_OK; |
| 921 } | 921 } |
| 922 | 922 |
| 923 int VP9DecoderImpl::ReturnFrame(const vpx_image_t* img, uint32_t timestamp) { | 923 int VP9DecoderImpl::ReturnFrame(const vpx_image_t* img, |
| 924 uint32_t timestamp, |
| 925 int64_t ntp_time_ms) { |
| 924 if (img == NULL) { | 926 if (img == NULL) { |
| 925 // Decoder OK and NULL image => No show frame. | 927 // Decoder OK and NULL image => No show frame. |
| 926 return WEBRTC_VIDEO_CODEC_NO_OUTPUT; | 928 return WEBRTC_VIDEO_CODEC_NO_OUTPUT; |
| 927 } | 929 } |
| 928 | 930 |
| 929 // This buffer contains all of |img|'s image data, a reference counted | 931 // This buffer contains all of |img|'s image data, a reference counted |
| 930 // Vp9FrameBuffer. (libvpx is done with the buffers after a few | 932 // Vp9FrameBuffer. (libvpx is done with the buffers after a few |
| 931 // vpx_codec_decode calls or vpx_codec_destroy). | 933 // vpx_codec_decode calls or vpx_codec_destroy). |
| 932 Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer = | 934 Vp9FrameBufferPool::Vp9FrameBuffer* img_buffer = |
| 933 static_cast<Vp9FrameBufferPool::Vp9FrameBuffer*>(img->fb_priv); | 935 static_cast<Vp9FrameBufferPool::Vp9FrameBuffer*>(img->fb_priv); |
| 934 // The buffer can be used directly by the VideoFrame (without copy) by | 936 // The buffer can be used directly by the VideoFrame (without copy) by |
| 935 // using a WrappedI420Buffer. | 937 // using a WrappedI420Buffer. |
| 936 rtc::scoped_refptr<WrappedI420Buffer> img_wrapped_buffer( | 938 rtc::scoped_refptr<WrappedI420Buffer> img_wrapped_buffer( |
| 937 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( | 939 new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( |
| 938 img->d_w, img->d_h, img->planes[VPX_PLANE_Y], | 940 img->d_w, img->d_h, img->planes[VPX_PLANE_Y], |
| 939 img->stride[VPX_PLANE_Y], img->planes[VPX_PLANE_U], | 941 img->stride[VPX_PLANE_Y], img->planes[VPX_PLANE_U], |
| 940 img->stride[VPX_PLANE_U], img->planes[VPX_PLANE_V], | 942 img->stride[VPX_PLANE_U], img->planes[VPX_PLANE_V], |
| 941 img->stride[VPX_PLANE_V], | 943 img->stride[VPX_PLANE_V], |
| 942 // WrappedI420Buffer's mechanism for allowing the release of its frame | 944 // WrappedI420Buffer's mechanism for allowing the release of its frame |
| 943 // buffer is through a callback function. This is where we should | 945 // buffer is through a callback function. This is where we should |
| 944 // release |img_buffer|. | 946 // release |img_buffer|. |
| 945 rtc::KeepRefUntilDone(img_buffer))); | 947 rtc::KeepRefUntilDone(img_buffer))); |
| 946 | 948 |
| 947 VideoFrame decoded_image; | 949 VideoFrame decoded_image; |
| 948 decoded_image.set_video_frame_buffer(img_wrapped_buffer); | 950 decoded_image.set_video_frame_buffer(img_wrapped_buffer); |
| 949 decoded_image.set_timestamp(timestamp); | 951 decoded_image.set_timestamp(timestamp); |
| 952 decoded_image.set_ntp_time_ms(ntp_time_ms); |
| 950 int ret = decode_complete_callback_->Decoded(decoded_image); | 953 int ret = decode_complete_callback_->Decoded(decoded_image); |
| 951 if (ret != 0) | 954 if (ret != 0) |
| 952 return ret; | 955 return ret; |
| 953 return WEBRTC_VIDEO_CODEC_OK; | 956 return WEBRTC_VIDEO_CODEC_OK; |
| 954 } | 957 } |
| 955 | 958 |
| 956 int VP9DecoderImpl::RegisterDecodeCompleteCallback( | 959 int VP9DecoderImpl::RegisterDecodeCompleteCallback( |
| 957 DecodedImageCallback* callback) { | 960 DecodedImageCallback* callback) { |
| 958 decode_complete_callback_ = callback; | 961 decode_complete_callback_ = callback; |
| 959 return WEBRTC_VIDEO_CODEC_OK; | 962 return WEBRTC_VIDEO_CODEC_OK; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 975 frame_buffer_pool_.ClearPool(); | 978 frame_buffer_pool_.ClearPool(); |
| 976 inited_ = false; | 979 inited_ = false; |
| 977 return WEBRTC_VIDEO_CODEC_OK; | 980 return WEBRTC_VIDEO_CODEC_OK; |
| 978 } | 981 } |
| 979 | 982 |
| 980 const char* VP9DecoderImpl::ImplementationName() const { | 983 const char* VP9DecoderImpl::ImplementationName() const { |
| 981 return "libvpx"; | 984 return "libvpx"; |
| 982 } | 985 } |
| 983 | 986 |
| 984 } // namespace webrtc | 987 } // namespace webrtc |
| OLD | NEW |