Bug 809558 - Turn on audiochannels for Android AudioTrack. r=kinetic
authorWes Johnston <wjohnston@mozilla.com>
Thu, 11 Apr 2013 15:37:35 -0700
changeset 128514 55a6fc3b5f421070b6dff19645f8543fb6cef594
parent 128513 ebcfc07b631511d2a5c9bd52abbe2ff76428a10f
child 128515 17d705ba2d9bd875559a69cbc7bfc240dcceaeb5
push id26355
push userwjohnston@mozilla.com
push dateThu, 11 Apr 2013 22:38:00 +0000
treeherdermozilla-inbound@55a6fc3b5f42 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetic
bugs809558
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 809558 - Turn on audiochannels for Android AudioTrack. r=kinetic
content/html/content/src/HTMLMediaElement.cpp
media/libcubeb/src/cubeb_audiotrack.c
--- a/content/html/content/src/HTMLMediaElement.cpp
+++ b/content/html/content/src/HTMLMediaElement.cpp
@@ -2153,17 +2153,17 @@ bool HTMLMediaElement::ParseAttribute(in
   }
 
   return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
                                               aResult);
 }
 
 bool HTMLMediaElement::CheckAudioChannelPermissions(const nsAString& aString)
 {
-#ifdef MOZ_B2G
+#ifdef ANDROID
   // Only normal channel doesn't need permission.
   if (!aString.EqualsASCII("normal")) {
     nsCOMPtr<nsIPermissionManager> permissionManager =
       do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
     if (!permissionManager) {
       return false;
     }
 
@@ -3208,17 +3208,17 @@ void HTMLMediaElement::SuspendOrResumeEl
       }
     }
   }
 }
 
 void HTMLMediaElement::NotifyOwnerDocumentActivityChanged()
 {
   nsIDocument* ownerDoc = OwnerDoc();
-#ifdef MOZ_B2G
+#ifdef ANDROID
   nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(OwnerDoc());
   if (domDoc) {
     bool hidden = false;
     domDoc->GetHidden(&hidden);
     // SetVisibilityState will update mChannelSuspended via the CanPlayChanged callback.
     if (mPlayingThroughTheAudioChannel && mAudioChannelAgent) {
       mAudioChannelAgent->SetVisibilityState(!hidden);
     }
@@ -3648,17 +3648,17 @@ ImageContainer* HTMLMediaElement::GetIma
   VideoFrameContainer* container = GetVideoFrameContainer();
   return container ? container->GetImageContainer() : nullptr;
 }
 
 nsresult HTMLMediaElement::UpdateChannelMuteState(bool aCanPlay)
 {
   // Only on B2G we mute the HTMLMediaElement following the rules of
   // AudioChannelService.
-#ifdef MOZ_B2G
+#ifdef ANDROID
   // We have to mute this channel:
   if (!aCanPlay && !mChannelSuspended) {
     mChannelSuspended = true;
     DispatchAsyncEvent(NS_LITERAL_STRING("mozinterruptbegin"));
   } else if (aCanPlay && mChannelSuspended) {
     mChannelSuspended = false;
     DispatchAsyncEvent(NS_LITERAL_STRING("mozinterruptend"));
   }
@@ -3667,17 +3667,17 @@ nsresult HTMLMediaElement::UpdateChannel
 #endif
 
   return NS_OK;
 }
 
 void HTMLMediaElement::UpdateAudioChannelPlayingState()
 {
   // The HTMLMediaElement is registered to the AudioChannelService only on B2G.
-#ifdef MOZ_B2G
+#ifdef ANDROID
   bool playingThroughTheAudioChannel =
      (!mPaused &&
       (HasAttr(kNameSpaceID_None, nsGkAtoms::loop) ||
        (mReadyState >= nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA &&
         !IsPlaybackEnded())));
   if (playingThroughTheAudioChannel != mPlayingThroughTheAudioChannel) {
     mPlayingThroughTheAudioChannel = playingThroughTheAudioChannel;
 
--- a/media/libcubeb/src/cubeb_audiotrack.c
+++ b/media/libcubeb/src/cubeb_audiotrack.c
@@ -141,44 +141,44 @@ audiotrack_version_is_froyo(cubeb * ctx)
 
 int
 audiotrack_get_min_frame_count(cubeb * ctx, cubeb_stream_params * params, int * min_frame_count)
 {
   status_t status;
   /* Recent Android have a getMinFrameCount method. On Froyo, we have to compute it by hand. */
   if (audiotrack_version_is_froyo(ctx)) {
     int samplerate, frame_count, latency, min_buffer_count;
-    status = ctx->klass.get_output_frame_count(&frame_count, AUDIO_STREAM_TYPE_MUSIC);
+    status = ctx->klass.get_output_frame_count(&frame_count, params->stream_type);
     if (status) {
       ALOG("error getting the output frame count.");
       return CUBEB_ERROR;
     }
-    status = ctx->klass.get_output_latency((uint32_t*)&latency, AUDIO_STREAM_TYPE_MUSIC);
+    status = ctx->klass.get_output_latency((uint32_t*)&latency, params->stream_type);
     if (status) {
       ALOG("error getting the output frame count.");
       return CUBEB_ERROR;
     }
-    status = ctx->klass.get_output_samplingrate(&samplerate, AUDIO_STREAM_TYPE_MUSIC);
+    status = ctx->klass.get_output_samplingrate(&samplerate, params->stream_type);
     if (status) {
       ALOG("error getting the output frame count.");
       return CUBEB_ERROR;
     }
 
     /* Those numbers were found reading the Android source. It is the minimum
      * numbers that will be accepted by the AudioTrack class, hence yielding the
      * best latency possible.
      * See https://android.googlesource.com/platform/frameworks/base/+/android-2.2.3_r2.1/media/libmedia/AudioTrack.cpp
      * around line 181 for Android 2.2 */
     min_buffer_count = latency / ((1000 * frame_count) / samplerate);
     min_buffer_count = min_buffer_count < 2 ? min_buffer_count : 2;
     *min_frame_count = (frame_count * params->rate * min_buffer_count) / samplerate;
     return CUBEB_OK;
   }
   /* Recent Android have a getMinFrameCount method. */
-  status = ctx->klass.get_min_frame_count(min_frame_count, AUDIO_STREAM_TYPE_MUSIC, params->rate);
+  status = ctx->klass.get_min_frame_count(min_frame_count, params->stream_type, params->rate);
   if (status != 0) {
     ALOG("error getting the min frame count");
     return CUBEB_ERROR;
   }
   return CUBEB_OK;
 }
 
 int
@@ -303,28 +303,28 @@ audiotrack_stream_init(cubeb * ctx, cube
   if (audiotrack_version_is_froyo(ctx)) {
     channels = stm->params.channels == 2 ? AUDIO_CHANNEL_OUT_STEREO_Froyo : AUDIO_CHANNEL_OUT_MONO_Froyo;
   } else {
     channels = stm->params.channels == 2 ? AUDIO_CHANNEL_OUT_STEREO_ICS : AUDIO_CHANNEL_OUT_MONO_ICS;
   }
 
   if (audiotrack_version_is_froyo(ctx)) {
     ctx->klass.ctor_froyo(stm->instance,
-                          AUDIO_STREAM_TYPE_MUSIC,
+                          stm->params.stream_type,
                           stm->params.rate,
                           AUDIO_FORMAT_PCM_16_BIT,
                           channels,
                           min_frame_count,
                           0,
                           audiotrack_refill,
                           stm,
                           0);
   } else {
     ctx->klass.ctor(stm->instance,
-                    AUDIO_STREAM_TYPE_MUSIC,
+                    stm->params.stream_type,
                     stm->params.rate,
                     AUDIO_FORMAT_PCM_16_BIT,
                     channels,
                     min_frame_count,
                     0,
                     audiotrack_refill,
                     stm,
                     0,