| OLD | NEW | 
|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "media/base/android/sdk_media_codec_bridge.h" | 5 #include "media/base/android/sdk_media_codec_bridge.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <limits> | 8 #include <limits> | 
| 9 #include <memory> | 9 #include <memory> | 
| 10 #include <utility> | 10 #include <utility> | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 78     default: | 78     default: | 
| 79       return std::string(); | 79       return std::string(); | 
| 80   } | 80   } | 
| 81 } | 81 } | 
| 82 | 82 | 
| 83 SdkMediaCodecBridge::SdkMediaCodecBridge(const std::string& mime, | 83 SdkMediaCodecBridge::SdkMediaCodecBridge(const std::string& mime, | 
| 84                                          bool is_secure, | 84                                          bool is_secure, | 
| 85                                          MediaCodecDirection direction, | 85                                          MediaCodecDirection direction, | 
| 86                                          bool require_software_codec) { | 86                                          bool require_software_codec) { | 
| 87   JNIEnv* env = AttachCurrentThread(); | 87   JNIEnv* env = AttachCurrentThread(); | 
| 88   CHECK(env); |  | 
| 89   DCHECK(!mime.empty()); | 88   DCHECK(!mime.empty()); | 
| 90   ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); | 89   ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); | 
| 91   j_media_codec_.Reset(Java_MediaCodecBridge_create( | 90   j_media_codec_.Reset(Java_MediaCodecBridge_create( | 
| 92       env, j_mime, is_secure, direction, require_software_codec)); | 91       env, j_mime, is_secure, direction, require_software_codec)); | 
| 93 } | 92 } | 
| 94 | 93 | 
| 95 SdkMediaCodecBridge::~SdkMediaCodecBridge() { | 94 SdkMediaCodecBridge::~SdkMediaCodecBridge() { | 
| 96   JNIEnv* env = AttachCurrentThread(); | 95   JNIEnv* env = AttachCurrentThread(); | 
| 97   CHECK(env); |  | 
| 98   if (j_media_codec_.obj()) | 96   if (j_media_codec_.obj()) | 
| 99     Java_MediaCodecBridge_release(env, j_media_codec_); | 97     Java_MediaCodecBridge_release(env, j_media_codec_); | 
| 100 } | 98 } | 
| 101 | 99 | 
| 102 bool SdkMediaCodecBridge::Start() { | 100 bool SdkMediaCodecBridge::Start() { | 
| 103   JNIEnv* env = AttachCurrentThread(); | 101   JNIEnv* env = AttachCurrentThread(); | 
| 104   return Java_MediaCodecBridge_start(env, j_media_codec_); | 102   return Java_MediaCodecBridge_start(env, j_media_codec_); | 
| 105 } | 103 } | 
| 106 | 104 | 
| 107 void SdkMediaCodecBridge::Stop() { | 105 void SdkMediaCodecBridge::Stop() { | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 150   if (status == MEDIA_CODEC_OK) | 148   if (status == MEDIA_CODEC_OK) | 
| 151     *channel_count = Java_GetOutputFormatResult_channelCount(env, result); | 149     *channel_count = Java_GetOutputFormatResult_channelCount(env, result); | 
| 152   return status; | 150   return status; | 
| 153 } | 151 } | 
| 154 | 152 | 
| 155 MediaCodecStatus SdkMediaCodecBridge::QueueInputBuffer( | 153 MediaCodecStatus SdkMediaCodecBridge::QueueInputBuffer( | 
| 156     int index, | 154     int index, | 
| 157     const uint8_t* data, | 155     const uint8_t* data, | 
| 158     size_t data_size, | 156     size_t data_size, | 
| 159     base::TimeDelta presentation_time) { | 157     base::TimeDelta presentation_time) { | 
| 160   DVLOG(3) << __PRETTY_FUNCTION__ << index << ": " << data_size; | 158   DVLOG(3) << __FUNCTION__ << index << ": " << data_size; | 
| 161   if (data_size > | 159   if (data_size > | 
| 162       base::checked_cast<size_t>(std::numeric_limits<int32_t>::max())) { | 160       base::checked_cast<size_t>(std::numeric_limits<int32_t>::max())) { | 
| 163     return MEDIA_CODEC_ERROR; | 161     return MEDIA_CODEC_ERROR; | 
| 164   } | 162   } | 
| 165   if (data && !FillInputBuffer(index, data, data_size)) | 163   if (data && !FillInputBuffer(index, data, data_size)) | 
| 166     return MEDIA_CODEC_ERROR; | 164     return MEDIA_CODEC_ERROR; | 
| 167   JNIEnv* env = AttachCurrentThread(); | 165   JNIEnv* env = AttachCurrentThread(); | 
| 168   return static_cast<MediaCodecStatus>(Java_MediaCodecBridge_queueInputBuffer( | 166   return static_cast<MediaCodecStatus>(Java_MediaCodecBridge_queueInputBuffer( | 
| 169       env, j_media_codec_, index, 0, data_size, | 167       env, j_media_codec_, index, 0, data_size, | 
| 170       presentation_time.InMicroseconds(), 0)); | 168       presentation_time.InMicroseconds(), 0)); | 
| 171 } | 169 } | 
| 172 | 170 | 
| 173 // TODO(timav): Combine this and above methods together keeping only the first | 171 // TODO(timav): Combine this and above methods together keeping only the first | 
| 174 // interface after we switch to Spitzer pipeline. | 172 // interface after we switch to Spitzer pipeline. | 
| 175 MediaCodecStatus SdkMediaCodecBridge::QueueSecureInputBuffer( | 173 MediaCodecStatus SdkMediaCodecBridge::QueueSecureInputBuffer( | 
| 176     int index, | 174     int index, | 
| 177     const uint8_t* data, | 175     const uint8_t* data, | 
| 178     size_t data_size, | 176     size_t data_size, | 
| 179     const std::vector<char>& key_id, | 177     const std::vector<char>& key_id, | 
| 180     const std::vector<char>& iv, | 178     const std::vector<char>& iv, | 
| 181     const SubsampleEntry* subsamples, | 179     const SubsampleEntry* subsamples, | 
| 182     int subsamples_size, | 180     int subsamples_size, | 
| 183     base::TimeDelta presentation_time) { | 181     base::TimeDelta presentation_time) { | 
| 184   DVLOG(3) << __PRETTY_FUNCTION__ << index << ": " << data_size; | 182   DVLOG(3) << __FUNCTION__ << index << ": " << data_size; | 
| 185   if (data_size > | 183   if (data_size > | 
| 186       base::checked_cast<size_t>(std::numeric_limits<int32_t>::max())) { | 184       base::checked_cast<size_t>(std::numeric_limits<int32_t>::max())) { | 
| 187     return MEDIA_CODEC_ERROR; | 185     return MEDIA_CODEC_ERROR; | 
| 188   } | 186   } | 
| 189   if (data && !FillInputBuffer(index, data, data_size)) | 187   if (data && !FillInputBuffer(index, data, data_size)) | 
| 190     return MEDIA_CODEC_ERROR; | 188     return MEDIA_CODEC_ERROR; | 
| 191 | 189 | 
| 192   JNIEnv* env = AttachCurrentThread(); | 190   JNIEnv* env = AttachCurrentThread(); | 
| 193   ScopedJavaLocalRef<jbyteArray> j_key_id = base::android::ToJavaByteArray( | 191   ScopedJavaLocalRef<jbyteArray> j_key_id = base::android::ToJavaByteArray( | 
| 194       env, reinterpret_cast<const uint8_t*>(key_id.data()), key_id.size()); | 192       env, reinterpret_cast<const uint8_t*>(key_id.data()), key_id.size()); | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 229       ToJavaIntArray(env, std::move(native_cypher_array), new_subsamples_size); | 227       ToJavaIntArray(env, std::move(native_cypher_array), new_subsamples_size); | 
| 230 | 228 | 
| 231   return static_cast<MediaCodecStatus>( | 229   return static_cast<MediaCodecStatus>( | 
| 232       Java_MediaCodecBridge_queueSecureInputBuffer( | 230       Java_MediaCodecBridge_queueSecureInputBuffer( | 
| 233           env, j_media_codec_.obj(), index, 0, j_iv.obj(), j_key_id.obj(), | 231           env, j_media_codec_.obj(), index, 0, j_iv.obj(), j_key_id.obj(), | 
| 234           clear_array, cypher_array, new_subsamples_size, | 232           clear_array, cypher_array, new_subsamples_size, | 
| 235           presentation_time.InMicroseconds())); | 233           presentation_time.InMicroseconds())); | 
| 236 } | 234 } | 
| 237 | 235 | 
| 238 void SdkMediaCodecBridge::QueueEOS(int input_buffer_index) { | 236 void SdkMediaCodecBridge::QueueEOS(int input_buffer_index) { | 
| 239   DVLOG(3) << __PRETTY_FUNCTION__ << ": " << input_buffer_index; | 237   DVLOG(3) << __FUNCTION__ << ": " << input_buffer_index; | 
| 240   JNIEnv* env = AttachCurrentThread(); | 238   JNIEnv* env = AttachCurrentThread(); | 
| 241   Java_MediaCodecBridge_queueInputBuffer( | 239   Java_MediaCodecBridge_queueInputBuffer( | 
| 242       env, j_media_codec_, input_buffer_index, 0, 0, 0, kBufferFlagEndOfStream); | 240       env, j_media_codec_, input_buffer_index, 0, 0, 0, kBufferFlagEndOfStream); | 
| 243 } | 241 } | 
| 244 | 242 | 
| 245 MediaCodecStatus SdkMediaCodecBridge::DequeueInputBuffer( | 243 MediaCodecStatus SdkMediaCodecBridge::DequeueInputBuffer( | 
| 246     base::TimeDelta timeout, | 244     base::TimeDelta timeout, | 
| 247     int* index) { | 245     int* index) { | 
| 248   JNIEnv* env = AttachCurrentThread(); | 246   JNIEnv* env = AttachCurrentThread(); | 
| 249   ScopedJavaLocalRef<jobject> result = Java_MediaCodecBridge_dequeueInputBuffer( | 247   ScopedJavaLocalRef<jobject> result = Java_MediaCodecBridge_dequeueInputBuffer( | 
| 250       env, j_media_codec_, timeout.InMicroseconds()); | 248       env, j_media_codec_, timeout.InMicroseconds()); | 
| 251   *index = Java_DequeueInputResult_index(env, result); | 249   *index = Java_DequeueInputResult_index(env, result); | 
| 252   MediaCodecStatus status = static_cast<MediaCodecStatus>( | 250   MediaCodecStatus status = static_cast<MediaCodecStatus>( | 
| 253       Java_DequeueInputResult_status(env, result)); | 251       Java_DequeueInputResult_status(env, result)); | 
| 254   DVLOG(3) << __PRETTY_FUNCTION__ << ": status: " << status | 252   DVLOG(3) << __FUNCTION__ << ": status: " << status << ", index: " << *index; | 
| 255            << ", index: " << *index; |  | 
| 256   return status; | 253   return status; | 
| 257 } | 254 } | 
| 258 | 255 | 
| 259 MediaCodecStatus SdkMediaCodecBridge::DequeueOutputBuffer( | 256 MediaCodecStatus SdkMediaCodecBridge::DequeueOutputBuffer( | 
| 260     base::TimeDelta timeout, | 257     base::TimeDelta timeout, | 
| 261     int* index, | 258     int* index, | 
| 262     size_t* offset, | 259     size_t* offset, | 
| 263     size_t* size, | 260     size_t* size, | 
| 264     base::TimeDelta* presentation_time, | 261     base::TimeDelta* presentation_time, | 
| 265     bool* end_of_stream, | 262     bool* end_of_stream, | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 277     *presentation_time = base::TimeDelta::FromMicroseconds( | 274     *presentation_time = base::TimeDelta::FromMicroseconds( | 
| 278         Java_DequeueOutputResult_presentationTimeMicroseconds(env, result)); | 275         Java_DequeueOutputResult_presentationTimeMicroseconds(env, result)); | 
| 279   } | 276   } | 
| 280   int flags = Java_DequeueOutputResult_flags(env, result); | 277   int flags = Java_DequeueOutputResult_flags(env, result); | 
| 281   if (end_of_stream) | 278   if (end_of_stream) | 
| 282     *end_of_stream = flags & kBufferFlagEndOfStream; | 279     *end_of_stream = flags & kBufferFlagEndOfStream; | 
| 283   if (key_frame) | 280   if (key_frame) | 
| 284     *key_frame = flags & kBufferFlagSyncFrame; | 281     *key_frame = flags & kBufferFlagSyncFrame; | 
| 285   MediaCodecStatus status = static_cast<MediaCodecStatus>( | 282   MediaCodecStatus status = static_cast<MediaCodecStatus>( | 
| 286       Java_DequeueOutputResult_status(env, result)); | 283       Java_DequeueOutputResult_status(env, result)); | 
| 287   DVLOG(3) << __PRETTY_FUNCTION__ << ": status: " << status | 284   DVLOG(3) << __FUNCTION__ << ": status: " << status << ", index: " << *index | 
| 288            << ", index: " << *index << ", offset: " << *offset | 285            << ", offset: " << *offset << ", size: " << *size | 
| 289            << ", size: " << *size << ", flags: " << flags; | 286            << ", flags: " << flags; | 
| 290   return status; | 287   return status; | 
| 291 } | 288 } | 
| 292 | 289 | 
| 293 void SdkMediaCodecBridge::ReleaseOutputBuffer(int index, bool render) { | 290 void SdkMediaCodecBridge::ReleaseOutputBuffer(int index, bool render) { | 
| 294   DVLOG(3) << __PRETTY_FUNCTION__ << ": " << index; | 291   DVLOG(3) << __FUNCTION__ << ": " << index; | 
| 295   JNIEnv* env = AttachCurrentThread(); | 292   JNIEnv* env = AttachCurrentThread(); | 
| 296   CHECK(env); |  | 
| 297 |  | 
| 298   Java_MediaCodecBridge_releaseOutputBuffer(env, j_media_codec_, index, render); | 293   Java_MediaCodecBridge_releaseOutputBuffer(env, j_media_codec_, index, render); | 
| 299 } | 294 } | 
| 300 | 295 | 
| 301 MediaCodecStatus SdkMediaCodecBridge::GetInputBuffer(int input_buffer_index, | 296 MediaCodecStatus SdkMediaCodecBridge::GetInputBuffer(int input_buffer_index, | 
| 302                                                      uint8_t** data, | 297                                                      uint8_t** data, | 
| 303                                                      size_t* capacity) { | 298                                                      size_t* capacity) { | 
| 304   JNIEnv* env = AttachCurrentThread(); | 299   JNIEnv* env = AttachCurrentThread(); | 
| 305   ScopedJavaLocalRef<jobject> j_buffer(Java_MediaCodecBridge_getInputBuffer( | 300   ScopedJavaLocalRef<jobject> j_buffer(Java_MediaCodecBridge_getInputBuffer( | 
| 306       env, j_media_codec_, input_buffer_index)); | 301       env, j_media_codec_, input_buffer_index)); | 
| 307   if (j_buffer.is_null()) | 302   if (j_buffer.is_null()) | 
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 700   if (adaptive_playback_supported_for_testing_ == 0) | 695   if (adaptive_playback_supported_for_testing_ == 0) | 
| 701     return false; | 696     return false; | 
| 702   else if (adaptive_playback_supported_for_testing_ > 0) | 697   else if (adaptive_playback_supported_for_testing_ > 0) | 
| 703     return true; | 698     return true; | 
| 704   JNIEnv* env = AttachCurrentThread(); | 699   JNIEnv* env = AttachCurrentThread(); | 
| 705   return Java_MediaCodecBridge_isAdaptivePlaybackSupported(env, media_codec(), | 700   return Java_MediaCodecBridge_isAdaptivePlaybackSupported(env, media_codec(), | 
| 706                                                            width, height); | 701                                                            width, height); | 
| 707 } | 702 } | 
| 708 | 703 | 
| 709 }  // namespace media | 704 }  // namespace media | 
| OLD | NEW | 
|---|