| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/base/android/ndk_media_codec_bridge.h" | 5 #include "media/base/android/ndk_media_codec_bridge.h" |
| 6 | 6 |
| 7 #include <media/NdkMediaError.h> | 7 #include <media/NdkMediaError.h> |
| 8 #include <media/NdkMediaFormat.h> | 8 #include <media/NdkMediaFormat.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool NdkMediaCodecBridge::Start() { | 62 bool NdkMediaCodecBridge::Start() { |
| 63 return AMEDIA_OK == AMediaCodec_start(media_codec_.get()); | 63 return AMEDIA_OK == AMediaCodec_start(media_codec_.get()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void NdkMediaCodecBridge::Stop() { | 66 void NdkMediaCodecBridge::Stop() { |
| 67 AMediaCodec_stop(media_codec_.get()); | 67 AMediaCodec_stop(media_codec_.get()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void NdkMediaCodecBridge::GetOutputFormat(int* width, int* height) { | 70 MediaCodecStatus NdkMediaCodecBridge::GetOutputSize(gfx::Size* size) { |
| 71 AMediaFormat* format = AMediaCodec_getOutputFormat(media_codec_.get()); | 71 AMediaFormat* format = AMediaCodec_getOutputFormat(media_codec_.get()); |
| 72 int left, right, bottom, top; | 72 int left, right, bottom, top; |
| 73 bool has_left = AMediaFormat_getInt32(format, kMediaFormatKeyCropLeft, &left); | 73 bool has_left = AMediaFormat_getInt32(format, kMediaFormatKeyCropLeft, &left); |
| 74 bool has_right = | 74 bool has_right = |
| 75 AMediaFormat_getInt32(format, kMediaFormatKeyCropRight, &right); | 75 AMediaFormat_getInt32(format, kMediaFormatKeyCropRight, &right); |
| 76 bool has_bottom = | 76 bool has_bottom = |
| 77 AMediaFormat_getInt32(format, kMediaFormatKeyCropBottom, &bottom); | 77 AMediaFormat_getInt32(format, kMediaFormatKeyCropBottom, &bottom); |
| 78 bool has_top = AMediaFormat_getInt32(format, kMediaFormatKeyCropTop, &top); | 78 bool has_top = AMediaFormat_getInt32(format, kMediaFormatKeyCropTop, &top); |
| 79 int width, height; |
| 79 if (has_left && has_right && has_bottom && has_top) { | 80 if (has_left && has_right && has_bottom && has_top) { |
| 80 // Use crop size as it is more accurate. right and bottom are inclusive. | 81 // Use crop size as it is more accurate. right and bottom are inclusive. |
| 81 *width = right - left + 1; | 82 width = right - left + 1; |
| 82 *height = top - bottom + 1; | 83 height = top - bottom + 1; |
| 83 } else { | 84 } else { |
| 84 AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_WIDTH, width); | 85 AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_WIDTH, &width); |
| 85 AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_HEIGHT, height); | 86 AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_HEIGHT, &height); |
| 86 } | 87 } |
| 88 size->SetSize(width, height); |
| 89 return MEDIA_CODEC_OK; |
| 87 } | 90 } |
| 88 | 91 |
| 89 int NdkMediaCodecBridge::GetOutputSamplingRate() { | 92 MediaCodecStatus NdkMediaCodecBridge::GetOutputSamplingRate( |
| 93 int* sampling_rate) { |
| 90 AMediaFormat* format = AMediaCodec_getOutputFormat(media_codec_.get()); | 94 AMediaFormat* format = AMediaCodec_getOutputFormat(media_codec_.get()); |
| 91 int sample_rate = 0; | 95 *sampling_rate = 0; |
| 92 AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_SAMPLE_RATE, &sample_rate); | 96 AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_SAMPLE_RATE, sampling_rate); |
| 93 DCHECK(sample_rate != 0); | 97 DCHECK_NE(*sampling_rate, 0); |
| 94 return sample_rate; | 98 return MEDIA_CODEC_OK; |
| 95 } | 99 } |
| 96 | 100 |
| 97 MediaCodecStatus NdkMediaCodecBridge::QueueInputBuffer( | 101 MediaCodecStatus NdkMediaCodecBridge::QueueInputBuffer( |
| 98 int index, | 102 int index, |
| 99 const uint8_t* data, | 103 const uint8_t* data, |
| 100 size_t data_size, | 104 size_t data_size, |
| 101 const base::TimeDelta& presentation_time) { | 105 const base::TimeDelta& presentation_time) { |
| 102 if (data_size > | 106 if (data_size > |
| 103 base::checked_cast<size_t>(std::numeric_limits<int32_t>::max())) { | 107 base::checked_cast<size_t>(std::numeric_limits<int32_t>::max())) { |
| 104 return MEDIA_CODEC_ERROR; | 108 return MEDIA_CODEC_ERROR; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 else if (*index == AMEDIACODEC_INFO_TRY_AGAIN_LATER) | 210 else if (*index == AMEDIACODEC_INFO_TRY_AGAIN_LATER) |
| 207 return MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER; | 211 return MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER; |
| 208 else | 212 else |
| 209 return MEDIA_CODEC_ERROR; | 213 return MEDIA_CODEC_ERROR; |
| 210 } | 214 } |
| 211 | 215 |
| 212 void NdkMediaCodecBridge::ReleaseOutputBuffer(int index, bool render) { | 216 void NdkMediaCodecBridge::ReleaseOutputBuffer(int index, bool render) { |
| 213 AMediaCodec_releaseOutputBuffer(media_codec_.get(), index, render); | 217 AMediaCodec_releaseOutputBuffer(media_codec_.get(), index, render); |
| 214 } | 218 } |
| 215 | 219 |
| 216 void NdkMediaCodecBridge::GetInputBuffer(int input_buffer_index, | 220 MediaCodecStatus NdkMediaCodecBridge::GetInputBuffer(int input_buffer_index, |
| 217 uint8_t** data, | 221 uint8_t** data, |
| 218 size_t* capacity) { | 222 size_t* capacity) { |
| 219 *data = AMediaCodec_getInputBuffer(media_codec_.get(), input_buffer_index, | 223 *data = AMediaCodec_getInputBuffer(media_codec_.get(), input_buffer_index, |
| 220 capacity); | 224 capacity); |
| 225 return MEDIA_CODEC_OK; |
| 221 } | 226 } |
| 222 | 227 |
| 223 void NdkMediaCodecBridge::CopyFromOutputBuffer(int index, | 228 MediaCodecStatus NdkMediaCodecBridge::CopyFromOutputBuffer(int index, |
| 224 size_t offset, | 229 size_t offset, |
| 225 void* dst, | 230 void* dst, |
| 226 size_t num) { | 231 size_t num) { |
| 227 size_t capacity; | 232 size_t capacity; |
| 228 const uint8_t* src_data = | 233 const uint8_t* src_data = |
| 229 AMediaCodec_getOutputBuffer(media_codec_.get(), index, &capacity); | 234 AMediaCodec_getOutputBuffer(media_codec_.get(), index, &capacity); |
| 230 CHECK_GE(capacity, offset + num); | 235 CHECK_GE(capacity, offset + num); |
| 231 memcpy(dst, src_data + offset, num); | 236 memcpy(dst, src_data + offset, num); |
| 237 return MEDIA_CODEC_OK; |
| 232 } | 238 } |
| 233 | 239 |
| 234 } // namespace media | 240 } // namespace media |
| OLD | NEW |