Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: media/base/android/webaudio_media_codec_bridge.cc

Issue 14522002: Handle decoding of vorbis files better on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/webaudio_media_codec_bridge.h" 5 #include "media/base/android/webaudio_media_codec_bridge.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
12 #include "base/android/jni_array.h" 12 #include "base/android/jni_array.h"
13 #include "base/android/jni_string.h" 13 #include "base/android/jni_string.h"
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/posix/eintr_wrapper.h" 16 #include "base/posix/eintr_wrapper.h"
17 #include "jni/WebAudioMediaCodecBridge_jni.h" 17 #include "jni/WebAudioMediaCodecBridge_jni.h"
18 18
19 19
20 using base::android::AttachCurrentThread; 20 using base::android::AttachCurrentThread;
21 21
22 namespace media { 22 namespace media {
23 23
24 void WebAudioMediaCodecBridge::RunWebAudioMediaCodec( 24 void WebAudioMediaCodecBridge::RunWebAudioMediaCodec(
25 base::SharedMemoryHandle encoded_audio_handle, 25 base::SharedMemoryHandle encoded_audio_handle,
26 base::FileDescriptor pcm_output) { 26 base::FileDescriptor pcm_output,
27 WebAudioMediaCodecBridge bridge(encoded_audio_handle, pcm_output); 27 size_t data_size) {
28 WebAudioMediaCodecBridge bridge(encoded_audio_handle, pcm_output, data_size);
28 29
29 bridge.DecodeInMemoryAudioFile(); 30 bridge.DecodeInMemoryAudioFile();
30 } 31 }
31 32
32 WebAudioMediaCodecBridge::WebAudioMediaCodecBridge( 33 WebAudioMediaCodecBridge::WebAudioMediaCodecBridge(
33 base::SharedMemoryHandle encoded_audio_handle, 34 base::SharedMemoryHandle encoded_audio_handle,
34 base::FileDescriptor pcm_output) 35 base::FileDescriptor pcm_output,
36 size_t data_size)
35 : encoded_audio_handle_(encoded_audio_handle.fd), 37 : encoded_audio_handle_(encoded_audio_handle.fd),
36 pcm_output_(pcm_output.fd) { 38 pcm_output_(pcm_output.fd),
39 data_size_(data_size) {
37 DVLOG(1) << "WebAudioMediaCodecBridge start **********************" 40 DVLOG(1) << "WebAudioMediaCodecBridge start **********************"
38 << "input fd = " << encoded_audio_handle_ 41 << "input fd = " << encoded_audio_handle_
39 << " output fd = " << pcm_output.fd; 42 << " output fd = " << pcm_output.fd;
40 } 43 }
41 44
42 WebAudioMediaCodecBridge::~WebAudioMediaCodecBridge() { 45 WebAudioMediaCodecBridge::~WebAudioMediaCodecBridge() {
43 if (close(pcm_output_)) { 46 if (close(pcm_output_)) {
44 DVLOG(1) << "Couldn't close output fd " << pcm_output_ 47 DVLOG(1) << "Couldn't close output fd " << pcm_output_
45 << ": " << strerror(errno); 48 << ": " << strerror(errno);
46 } 49 }
47 50
48 if (close(encoded_audio_handle_)) { 51 if (close(encoded_audio_handle_)) {
49 DVLOG(1) << "Couldn't close shared mem fd " << encoded_audio_handle_ 52 DVLOG(1) << "Couldn't close shared mem fd " << encoded_audio_handle_
50 << ": " << strerror(errno); 53 << ": " << strerror(errno);
51 } 54 }
52 } 55 }
53 56
54 bool WebAudioMediaCodecBridge::DecodeInMemoryAudioFile() { 57 bool WebAudioMediaCodecBridge::DecodeInMemoryAudioFile() {
55 // Process the encoded data from |encoded_data_handle_|. 58 // Process the encoded data from |encoded_data_handle_|.
56 59
57 JNIEnv* env = AttachCurrentThread(); 60 JNIEnv* env = AttachCurrentThread();
58 CHECK(env); 61 CHECK(env);
59 jboolean decoded = Java_WebAudioMediaCodecBridge_decodeAudioFile( 62 jboolean decoded = Java_WebAudioMediaCodecBridge_decodeAudioFile(
60 env, 63 env,
61 base::android::GetApplicationContext(), 64 base::android::GetApplicationContext(),
62 reinterpret_cast<intptr_t>(this), 65 reinterpret_cast<intptr_t>(this),
63 encoded_audio_handle_); 66 encoded_audio_handle_,
67 data_size_);
64 68
65 DVLOG(1) << "decoded = " << decoded; 69 DVLOG(1) << "decoded = " << decoded;
66 return decoded; 70 return decoded;
67 } 71 }
68 72
69 void WebAudioMediaCodecBridge::InitializeDestination( 73 void WebAudioMediaCodecBridge::InitializeDestination(
70 JNIEnv* env, 74 JNIEnv* env,
71 jobject /*java object*/, 75 jobject /*java object*/,
72 jint channel_count, 76 jint channel_count,
73 jint sample_rate, 77 jint sample_rate,
74 jlong duration_microsec, 78 jlong duration_microsec) {
75 jboolean is_vorbis) {
76 // Send information about this audio file: number of channels, 79 // Send information about this audio file: number of channels,
77 // sample rate (Hz), number of frames, a flag indicating whether 80 // sample rate (Hz), number of frames, a flag indicating whether
78 // this file is an audio/vorbis file. Information is sent as a set of 81 // this file is an audio/vorbis file. Information is sent as a set of
79 // 4 longs. This must be coordinated with DecodeAudioFileData! 82 // 4 longs. This must be coordinated with DecodeAudioFileData!
80 83
81 unsigned long info[4] = {static_cast<unsigned long>(channel_count), 84 unsigned long info[3] = {static_cast<unsigned long>(channel_count),
DaleCurtis 2013/04/30 17:44:17 Can you just drop the 3 and let it auto size? All
Raymond Toy (Google) 2013/04/30 17:57:49 The static casts were added by benm@ to fix a WebV
82 static_cast<unsigned long>(sample_rate), 85 static_cast<unsigned long>(sample_rate),
83 // The number of frames is the duration of the file 86 // The number of frames is the duration of the file
84 // (in microseconds) times the sample rate. 87 // (in microseconds) times the sample rate.
85 static_cast<unsigned long>( 88 static_cast<unsigned long>(
86 0.5 + (duration_microsec * 0.000001 * 89 0.5 + (duration_microsec * 0.000001 *
87 sample_rate)), 90 sample_rate))};
88 is_vorbis ? 1ul : 0ul};
89 91
90 DVLOG(1) << "InitializeDestination:" 92 DVLOG(1) << "InitializeDestination:"
91 << " channel count = " << channel_count 93 << " channel count = " << channel_count
92 << " rate = " << sample_rate 94 << " rate = " << sample_rate
93 << " duration = " << duration_microsec << " microsec" 95 << " duration = " << duration_microsec << " microsec";
94 << " vorbis = " << (is_vorbis ? "yes" : "no");
95 96
96 HANDLE_EINTR(write(pcm_output_, info, sizeof(info))); 97 HANDLE_EINTR(write(pcm_output_, info, sizeof(info)));
97 } 98 }
98 99
99 void WebAudioMediaCodecBridge::OnChunkDecoded( 100 void WebAudioMediaCodecBridge::OnChunkDecoded(
100 JNIEnv* env, 101 JNIEnv* env,
101 jobject /*java object*/, 102 jobject /*java object*/,
102 jobject buf, 103 jobject buf,
103 jint buf_size) { 104 jint buf_size) {
104 105
(...skipping 16 matching lines...) Expand all
121 count -= bytes_written; 122 count -= bytes_written;
122 buffer += bytes_written; 123 buffer += bytes_written;
123 } 124 }
124 } 125 }
125 126
126 bool WebAudioMediaCodecBridge::RegisterWebAudioMediaCodecBridge(JNIEnv* env) { 127 bool WebAudioMediaCodecBridge::RegisterWebAudioMediaCodecBridge(JNIEnv* env) {
127 return RegisterNativesImpl(env); 128 return RegisterNativesImpl(env);
128 } 129 }
129 130
130 } // namespace 131 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698