| 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/media_codec_bridge.h" | 5 #include "media/base/android/media_codec_bridge.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/android/build_info.h" | 10 #include "base/android/build_info.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // static | 81 // static |
| 82 bool MediaCodecBridge::CanDecode(const std::string& codec, bool is_secure) { | 82 bool MediaCodecBridge::CanDecode(const std::string& codec, bool is_secure) { |
| 83 JNIEnv* env = AttachCurrentThread(); | 83 JNIEnv* env = AttachCurrentThread(); |
| 84 std::string mime = CodecTypeToMimeType(codec); | 84 std::string mime = CodecTypeToMimeType(codec); |
| 85 if (mime.empty()) | 85 if (mime.empty()) |
| 86 return false; | 86 return false; |
| 87 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); | 87 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); |
| 88 return !Java_MediaCodecBridge_create(env, j_mime.obj(), is_secure).is_null(); | 88 return !Java_MediaCodecBridge_create(env, j_mime.obj(), is_secure).is_null(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // TODO(xhwang): Support creating secure MediaCodecBridge. | 91 MediaCodecBridge::MediaCodecBridge(const std::string& mime, bool is_secure) { |
| 92 MediaCodecBridge::MediaCodecBridge(const std::string& mime) { | |
| 93 JNIEnv* env = AttachCurrentThread(); | 92 JNIEnv* env = AttachCurrentThread(); |
| 94 CHECK(env); | 93 CHECK(env); |
| 95 | 94 |
| 96 DCHECK(!mime.empty()); | 95 DCHECK(!mime.empty()); |
| 97 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); | 96 ScopedJavaLocalRef<jstring> j_mime = ConvertUTF8ToJavaString(env, mime); |
| 98 j_media_codec_.Reset(Java_MediaCodecBridge_create(env, j_mime.obj(), false)); | 97 j_media_codec_.Reset( |
| 98 Java_MediaCodecBridge_create(env, j_mime.obj(), is_secure)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 MediaCodecBridge::~MediaCodecBridge() { | 101 MediaCodecBridge::~MediaCodecBridge() { |
| 102 JNIEnv* env = AttachCurrentThread(); | 102 JNIEnv* env = AttachCurrentThread(); |
| 103 CHECK(env); | 103 CHECK(env); |
| 104 if (j_media_codec_.obj()) | 104 if (j_media_codec_.obj()) |
| 105 Java_MediaCodecBridge_release(env, j_media_codec_.obj()); | 105 Java_MediaCodecBridge_release(env, j_media_codec_.obj()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void MediaCodecBridge::StartInternal() { | 108 void MediaCodecBridge::StartInternal() { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 // TODO(qinmin): Handling the case that not all the data can be copied. | 254 // TODO(qinmin): Handling the case that not all the data can be copied. |
| 255 DCHECK(size_to_copy == size) << | 255 DCHECK(size_to_copy == size) << |
| 256 "Failed to fill all the data into the input buffer. Size to fill: " | 256 "Failed to fill all the data into the input buffer. Size to fill: " |
| 257 << size << ". Size filled: " << size_to_copy; | 257 << size << ". Size filled: " << size_to_copy; |
| 258 if (size_to_copy > 0) | 258 if (size_to_copy > 0) |
| 259 memcpy(direct_buffer, data, size_to_copy); | 259 memcpy(direct_buffer, data, size_to_copy); |
| 260 return size_to_copy; | 260 return size_to_copy; |
| 261 } | 261 } |
| 262 | 262 |
| 263 AudioCodecBridge::AudioCodecBridge(const std::string& mime) | 263 AudioCodecBridge::AudioCodecBridge(const std::string& mime) |
| 264 : MediaCodecBridge(mime) { | 264 // Audio codec doesn't care about security level. |
| 265 : MediaCodecBridge(mime, false) { |
| 265 } | 266 } |
| 266 | 267 |
| 267 bool AudioCodecBridge::Start( | 268 bool AudioCodecBridge::Start( |
| 268 const AudioCodec codec, int sample_rate, int channel_count, | 269 const AudioCodec codec, int sample_rate, int channel_count, |
| 269 const uint8* extra_data, size_t extra_data_size, bool play_audio, | 270 const uint8* extra_data, size_t extra_data_size, bool play_audio, |
| 270 jobject media_crypto) { | 271 jobject media_crypto) { |
| 271 JNIEnv* env = AttachCurrentThread(); | 272 JNIEnv* env = AttachCurrentThread(); |
| 272 | 273 |
| 273 if (!media_codec()) | 274 if (!media_codec()) |
| 274 return false; | 275 return false; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 base::android::ToJavaByteArray(env, buffer, numBytes); | 413 base::android::ToJavaByteArray(env, buffer, numBytes); |
| 413 Java_MediaCodecBridge_playOutputBuffer( | 414 Java_MediaCodecBridge_playOutputBuffer( |
| 414 env, media_codec(), byte_array.obj()); | 415 env, media_codec(), byte_array.obj()); |
| 415 } | 416 } |
| 416 | 417 |
| 417 void AudioCodecBridge::SetVolume(double volume) { | 418 void AudioCodecBridge::SetVolume(double volume) { |
| 418 JNIEnv* env = AttachCurrentThread(); | 419 JNIEnv* env = AttachCurrentThread(); |
| 419 Java_MediaCodecBridge_setVolume(env, media_codec(), volume); | 420 Java_MediaCodecBridge_setVolume(env, media_codec(), volume); |
| 420 } | 421 } |
| 421 | 422 |
| 422 VideoCodecBridge::VideoCodecBridge(const std::string& mime) | 423 VideoCodecBridge::VideoCodecBridge(const std::string& mime, bool is_secure) |
| 423 : MediaCodecBridge(mime) { | 424 : MediaCodecBridge(mime, is_secure) { |
| 424 } | 425 } |
| 425 | 426 |
| 426 bool VideoCodecBridge::Start( | 427 bool VideoCodecBridge::Start( |
| 427 const VideoCodec codec, const gfx::Size& size, jobject surface, | 428 const VideoCodec codec, const gfx::Size& size, jobject surface, |
| 428 jobject media_crypto) { | 429 jobject media_crypto) { |
| 429 JNIEnv* env = AttachCurrentThread(); | 430 JNIEnv* env = AttachCurrentThread(); |
| 430 | 431 |
| 431 if (!media_codec()) | 432 if (!media_codec()) |
| 432 return false; | 433 return false; |
| 433 | 434 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 447 } | 448 } |
| 448 StartInternal(); | 449 StartInternal(); |
| 449 return true; | 450 return true; |
| 450 } | 451 } |
| 451 | 452 |
| 452 AudioCodecBridge* AudioCodecBridge::Create(const AudioCodec codec) { | 453 AudioCodecBridge* AudioCodecBridge::Create(const AudioCodec codec) { |
| 453 const std::string mime = AudioCodecToMimeType(codec); | 454 const std::string mime = AudioCodecToMimeType(codec); |
| 454 return mime.empty() ? NULL : new AudioCodecBridge(mime); | 455 return mime.empty() ? NULL : new AudioCodecBridge(mime); |
| 455 } | 456 } |
| 456 | 457 |
| 457 VideoCodecBridge* VideoCodecBridge::Create(const VideoCodec codec) { | 458 VideoCodecBridge* VideoCodecBridge::Create(const VideoCodec codec, |
| 459 bool is_secure) { |
| 458 const std::string mime = VideoCodecToMimeType(codec); | 460 const std::string mime = VideoCodecToMimeType(codec); |
| 459 return mime.empty() ? NULL : new VideoCodecBridge(mime); | 461 return mime.empty() ? NULL : new VideoCodecBridge(mime, is_secure); |
| 460 } | 462 } |
| 461 | 463 |
| 462 bool MediaCodecBridge::RegisterMediaCodecBridge(JNIEnv* env) { | 464 bool MediaCodecBridge::RegisterMediaCodecBridge(JNIEnv* env) { |
| 463 return RegisterNativesImpl(env); | 465 return RegisterNativesImpl(env); |
| 464 } | 466 } |
| 465 | 467 |
| 466 } // namespace media | 468 } // namespace media |
| OLD | NEW |