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

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 #include "media/base/android/webaudio_media_codec_info.h"
18 19
19 20
20 using base::android::AttachCurrentThread; 21 using base::android::AttachCurrentThread;
21 22
22 namespace media { 23 namespace media {
23 24
24 void WebAudioMediaCodecBridge::RunWebAudioMediaCodec( 25 void WebAudioMediaCodecBridge::RunWebAudioMediaCodec(
25 base::SharedMemoryHandle encoded_audio_handle, 26 base::SharedMemoryHandle encoded_audio_handle,
26 base::FileDescriptor pcm_output) { 27 base::FileDescriptor pcm_output,
27 WebAudioMediaCodecBridge bridge(encoded_audio_handle, pcm_output); 28 size_t data_size) {
29 WebAudioMediaCodecBridge bridge(encoded_audio_handle, pcm_output, data_size);
28 30
29 bridge.DecodeInMemoryAudioFile(); 31 bridge.DecodeInMemoryAudioFile();
30 } 32 }
31 33
32 WebAudioMediaCodecBridge::WebAudioMediaCodecBridge( 34 WebAudioMediaCodecBridge::WebAudioMediaCodecBridge(
33 base::SharedMemoryHandle encoded_audio_handle, 35 base::SharedMemoryHandle encoded_audio_handle,
34 base::FileDescriptor pcm_output) 36 base::FileDescriptor pcm_output,
37 size_t data_size)
35 : encoded_audio_handle_(encoded_audio_handle.fd), 38 : encoded_audio_handle_(encoded_audio_handle.fd),
36 pcm_output_(pcm_output.fd) { 39 pcm_output_(pcm_output.fd),
40 data_size_(data_size) {
37 DVLOG(1) << "WebAudioMediaCodecBridge start **********************" 41 DVLOG(1) << "WebAudioMediaCodecBridge start **********************"
38 << "input fd = " << encoded_audio_handle_ 42 << "input fd = " << encoded_audio_handle_
39 << " output fd = " << pcm_output.fd; 43 << " output fd = " << pcm_output.fd;
40 } 44 }
41 45
42 WebAudioMediaCodecBridge::~WebAudioMediaCodecBridge() { 46 WebAudioMediaCodecBridge::~WebAudioMediaCodecBridge() {
43 if (close(pcm_output_)) { 47 if (close(pcm_output_)) {
44 DVLOG(1) << "Couldn't close output fd " << pcm_output_ 48 DVLOG(1) << "Couldn't close output fd " << pcm_output_
45 << ": " << strerror(errno); 49 << ": " << strerror(errno);
46 } 50 }
47 51
48 if (close(encoded_audio_handle_)) { 52 if (close(encoded_audio_handle_)) {
49 DVLOG(1) << "Couldn't close shared mem fd " << encoded_audio_handle_ 53 DVLOG(1) << "Couldn't close shared mem fd " << encoded_audio_handle_
50 << ": " << strerror(errno); 54 << ": " << strerror(errno);
51 } 55 }
52 } 56 }
53 57
54 bool WebAudioMediaCodecBridge::DecodeInMemoryAudioFile() { 58 bool WebAudioMediaCodecBridge::DecodeInMemoryAudioFile() {
55 // Process the encoded data from |encoded_data_handle_|. 59 // Process the encoded data from |encoded_data_handle_|.
56 60
57 JNIEnv* env = AttachCurrentThread(); 61 JNIEnv* env = AttachCurrentThread();
58 CHECK(env); 62 CHECK(env);
59 jboolean decoded = Java_WebAudioMediaCodecBridge_decodeAudioFile( 63 jboolean decoded = Java_WebAudioMediaCodecBridge_decodeAudioFile(
60 env, 64 env,
61 base::android::GetApplicationContext(), 65 base::android::GetApplicationContext(),
62 reinterpret_cast<intptr_t>(this), 66 reinterpret_cast<intptr_t>(this),
63 encoded_audio_handle_); 67 encoded_audio_handle_,
68 data_size_);
64 69
65 DVLOG(1) << "decoded = " << decoded; 70 DVLOG(1) << "decoded = " << decoded;
66 return decoded; 71 return decoded;
67 } 72 }
68 73
69 void WebAudioMediaCodecBridge::InitializeDestination( 74 void WebAudioMediaCodecBridge::InitializeDestination(
70 JNIEnv* env, 75 JNIEnv* env,
71 jobject /*java object*/, 76 jobject /*java object*/,
72 jint channel_count, 77 jint channel_count,
73 jint sample_rate, 78 jint sample_rate,
74 jlong duration_microsec, 79 jlong duration_microsec) {
75 jboolean is_vorbis) {
76 // Send information about this audio file: number of channels, 80 // Send information about this audio file: number of channels,
77 // sample rate (Hz), number of frames, a flag indicating whether 81 // sample rate (Hz), and the number of frames.
78 // this file is an audio/vorbis file. Information is sent as a set of 82 struct WebAudioMediaCodecInfo info = {
79 // 4 longs. This must be coordinated with DecodeAudioFileData! 83 static_cast<unsigned long>(channel_count),
80 84 static_cast<unsigned long>(sample_rate),
81 unsigned long info[4] = {static_cast<unsigned long>(channel_count), 85 // The number of frames is the duration of the file
82 static_cast<unsigned long>(sample_rate), 86 // (in microseconds) times the sample rate.
83 // The number of frames is the duration of the file 87 static_cast<unsigned long>(
84 // (in microseconds) times the sample rate. 88 0.5 + (duration_microsec * 0.000001 *
85 static_cast<unsigned long>( 89 sample_rate))
86 0.5 + (duration_microsec * 0.000001 * 90 };
87 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
105 if (buf_size <= 0 || !buf) 106 if (buf_size <= 0 || !buf)
106 return; 107 return;
(...skipping 14 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
« no previous file with comments | « media/base/android/webaudio_media_codec_bridge.h ('k') | media/base/android/webaudio_media_codec_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698