| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 if (codecSettings->width < 1 || codecSettings->height < 1) { | 50 if (codecSettings->width < 1 || codecSettings->height < 1) { |
| 51 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; | 51 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Allocating encoded memory. | 54 // Allocating encoded memory. |
| 55 if (_encodedImage._buffer != NULL) { | 55 if (_encodedImage._buffer != NULL) { |
| 56 delete[] _encodedImage._buffer; | 56 delete[] _encodedImage._buffer; |
| 57 _encodedImage._buffer = NULL; | 57 _encodedImage._buffer = NULL; |
| 58 _encodedImage._size = 0; | 58 _encodedImage._size = 0; |
| 59 } | 59 } |
| 60 const size_t newSize = | 60 const size_t newSize = CalcBufferSize(VideoType::kI420, codecSettings->width, |
| 61 CalcBufferSize(kI420, codecSettings->width, codecSettings->height) + | 61 codecSettings->height) + |
| 62 kI420HeaderSize; | 62 kI420HeaderSize; |
| 63 uint8_t* newBuffer = new uint8_t[newSize]; | 63 uint8_t* newBuffer = new uint8_t[newSize]; |
| 64 if (newBuffer == NULL) { | 64 if (newBuffer == NULL) { |
| 65 return WEBRTC_VIDEO_CODEC_MEMORY; | 65 return WEBRTC_VIDEO_CODEC_MEMORY; |
| 66 } | 66 } |
| 67 _encodedImage._size = newSize; | 67 _encodedImage._size = newSize; |
| 68 _encodedImage._buffer = newBuffer; | 68 _encodedImage._buffer = newBuffer; |
| 69 | 69 |
| 70 // If no memory allocation, no point to init. | 70 // If no memory allocation, no point to init. |
| 71 _inited = true; | 71 _inited = true; |
| 72 return WEBRTC_VIDEO_CODEC_OK; | 72 return WEBRTC_VIDEO_CODEC_OK; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 89 | 89 |
| 90 int width = inputImage.width(); | 90 int width = inputImage.width(); |
| 91 if (width > std::numeric_limits<uint16_t>::max()) { | 91 if (width > std::numeric_limits<uint16_t>::max()) { |
| 92 return WEBRTC_VIDEO_CODEC_ERR_SIZE; | 92 return WEBRTC_VIDEO_CODEC_ERR_SIZE; |
| 93 } | 93 } |
| 94 int height = inputImage.height(); | 94 int height = inputImage.height(); |
| 95 if (height > std::numeric_limits<uint16_t>::max()) { | 95 if (height > std::numeric_limits<uint16_t>::max()) { |
| 96 return WEBRTC_VIDEO_CODEC_ERR_SIZE; | 96 return WEBRTC_VIDEO_CODEC_ERR_SIZE; |
| 97 } | 97 } |
| 98 | 98 |
| 99 size_t req_length = | 99 size_t req_length = CalcBufferSize(VideoType::kI420, inputImage.width(), |
| 100 CalcBufferSize(kI420, inputImage.width(), inputImage.height()) + | 100 inputImage.height()) + |
| 101 kI420HeaderSize; | 101 kI420HeaderSize; |
| 102 if (_encodedImage._size > req_length) { | 102 if (_encodedImage._size > req_length) { |
| 103 // Reallocate buffer. | 103 // Reallocate buffer. |
| 104 delete[] _encodedImage._buffer; | 104 delete[] _encodedImage._buffer; |
| 105 | 105 |
| 106 _encodedImage._buffer = new uint8_t[req_length]; | 106 _encodedImage._buffer = new uint8_t[req_length]; |
| 107 _encodedImage._size = req_length; | 107 _encodedImage._size = req_length; |
| 108 } | 108 } |
| 109 | 109 |
| 110 uint8_t* buffer = _encodedImage._buffer; | 110 uint8_t* buffer = _encodedImage._buffer; |
| 111 | 111 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 } | 186 } |
| 187 | 187 |
| 188 const uint8_t* buffer = inputImage._buffer; | 188 const uint8_t* buffer = inputImage._buffer; |
| 189 uint16_t width, height; | 189 uint16_t width, height; |
| 190 | 190 |
| 191 buffer = ExtractHeader(buffer, &width, &height); | 191 buffer = ExtractHeader(buffer, &width, &height); |
| 192 _width = width; | 192 _width = width; |
| 193 _height = height; | 193 _height = height; |
| 194 | 194 |
| 195 // Verify that the available length is sufficient: | 195 // Verify that the available length is sufficient: |
| 196 size_t req_length = CalcBufferSize(kI420, _width, _height) + kI420HeaderSize; | 196 size_t req_length = |
| 197 CalcBufferSize(VideoType::kI420, _width, _height) + kI420HeaderSize; |
| 197 | 198 |
| 198 if (req_length > inputImage._length) { | 199 if (req_length > inputImage._length) { |
| 199 return WEBRTC_VIDEO_CODEC_ERROR; | 200 return WEBRTC_VIDEO_CODEC_ERROR; |
| 200 } | 201 } |
| 201 // Set decoded image parameters. | 202 // Set decoded image parameters. |
| 202 int half_width = (_width + 1) / 2; | 203 int half_width = (_width + 1) / 2; |
| 203 rtc::scoped_refptr<webrtc::I420Buffer> frame_buffer = | 204 rtc::scoped_refptr<webrtc::I420Buffer> frame_buffer = |
| 204 I420Buffer::Create(_width, _height, _width, half_width, half_width); | 205 I420Buffer::Create(_width, _height, _width, half_width, half_width); |
| 205 | 206 |
| 206 // Converting from raw buffer I420Buffer. | 207 // Converting from raw buffer I420Buffer. |
| 207 int ret = ConvertToI420(kI420, buffer, 0, 0, _width, _height, 0, | 208 int ret = ConvertToI420(VideoType::kI420, buffer, 0, 0, _width, _height, 0, |
| 208 kVideoRotation_0, frame_buffer.get()); | 209 kVideoRotation_0, frame_buffer.get()); |
| 209 if (ret < 0) { | 210 if (ret < 0) { |
| 210 return WEBRTC_VIDEO_CODEC_MEMORY; | 211 return WEBRTC_VIDEO_CODEC_MEMORY; |
| 211 } | 212 } |
| 212 | 213 |
| 213 VideoFrame decoded_image(frame_buffer, inputImage._timeStamp, 0, | 214 VideoFrame decoded_image(frame_buffer, inputImage._timeStamp, 0, |
| 214 webrtc::kVideoRotation_0); | 215 webrtc::kVideoRotation_0); |
| 215 _decodeCompleteCallback->Decoded(decoded_image); | 216 _decodeCompleteCallback->Decoded(decoded_image); |
| 216 return WEBRTC_VIDEO_CODEC_OK; | 217 return WEBRTC_VIDEO_CODEC_OK; |
| 217 } | 218 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 231 DecodedImageCallback* callback) { | 232 DecodedImageCallback* callback) { |
| 232 _decodeCompleteCallback = callback; | 233 _decodeCompleteCallback = callback; |
| 233 return WEBRTC_VIDEO_CODEC_OK; | 234 return WEBRTC_VIDEO_CODEC_OK; |
| 234 } | 235 } |
| 235 | 236 |
| 236 int I420Decoder::Release() { | 237 int I420Decoder::Release() { |
| 237 _inited = false; | 238 _inited = false; |
| 238 return WEBRTC_VIDEO_CODEC_OK; | 239 return WEBRTC_VIDEO_CODEC_OK; |
| 239 } | 240 } |
| 240 } // namespace webrtc | 241 } // namespace webrtc |
| OLD | NEW |