Skip to content

Commit

Permalink
Bug 976172 - Part 1 Changes in MediaOmxDecoder to enable audio offloa…
Browse files Browse the repository at this point in the history
…ding r=roc

This adds support in MediaOmxDecoder to dynamically switch between
MediaDecoderStateMachine and AudioOffloadPlayer
  • Loading branch information
Vasanth1789 committed Apr 8, 2014
1 parent 81db06b commit 27518df
Show file tree
Hide file tree
Showing 13 changed files with 453 additions and 17 deletions.
2 changes: 1 addition & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ if test -n "$gonkdir" ; then

case "$ANDROID_VERSION" in
15)
GONK_INCLUDES="-I$gonkdir/frameworks/base/opengl/include -I$gonkdir/frameworks/base/native/include -I$gonkdir/frameworks/base/include -I$gonkdir/frameworks/base/services/camera -I$gonkdir/frameworks/base/include/media/stagefright -I$gonkdir/frameworks/base/include/media/stagefright/openmax -I$gonkdir/frameworks/base/media/libstagefright/rtsp -I$gonkdir/frameworks/base/media/libstagefright/include -I$gonkdir/external/dbus -I$gonkdir/external/bluetooth/bluez/lib -I$gonkdir/dalvik/libnativehelper/include/nativehelper"
GONK_INCLUDES="-I$gonkdir/frameworks/base/opengl/include -I$gonkdir/frameworks/base/native/include -I$gonkdir/frameworks/base/include -I$gonkdir/frameworks/base/services/camera -I$gonkdir/frameworks/base/include/media/ -I$gonkdir/frameworks/base/include/media/stagefright -I$gonkdir/frameworks/base/include/media/stagefright/openmax -I$gonkdir/frameworks/base/media/libstagefright/rtsp -I$gonkdir/frameworks/base/media/libstagefright/include -I$gonkdir/external/dbus -I$gonkdir/external/bluetooth/bluez/lib -I$gonkdir/dalvik/libnativehelper/include/nativehelper"
MOZ_B2G_BT=1
MOZ_B2G_BT_BLUEZ=1
MOZ_NFC=1
Expand Down
3 changes: 3 additions & 0 deletions content/html/content/public/HTMLMediaElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class nsIRunnable;
namespace mozilla {
namespace dom {

// Number of milliseconds between timeupdate events as defined by spec
#define TIMEUPDATE_MS 250

class MediaError;
class MediaSource;
class TextTrackList;
Expand Down
4 changes: 1 addition & 3 deletions content/html/content/src/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ using mozilla::net::nsMediaFragmentURIParser;
namespace mozilla {
namespace dom {

// Number of milliseconds between timeupdate events as defined by spec
#define TIMEUPDATE_MS 250

// Used by AudioChannel for suppresssing the volume to this ratio.
#define FADED_VOLUME_RATIO 0.25

Expand Down Expand Up @@ -3385,6 +3382,7 @@ void HTMLMediaElement::NotifyOwnerDocumentActivityChanged()
nsIDocument* ownerDoc = OwnerDoc();

if (mDecoder) {
mDecoder->SetElementVisibility(!ownerDoc->Hidden());
mDecoder->SetDormantIfNecessary(ownerDoc->Hidden());
}

Expand Down
6 changes: 6 additions & 0 deletions content/media/AbstractMediaDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ class AbstractMediaDecoder : public nsISupports
// required to begin playback have been acquired. Can be called on any thread.
virtual void NotifyWaitingForResourcesStatusChanged() = 0;

// Called by Reader if the current audio track can be offloaded
virtual void SetCanOffloadAudio(bool aCanOffloadAudio) {}

// Called from HTMLMediaElement when owner document activity changes
virtual void SetElementVisibility(bool aIsVisible) {}

// Stack based class to assist in notifying the frame statistics of
// parsed and decoded frames. Use inside video demux & decode functions
// to ensure all parsed and decoded frames are reported on all return paths.
Expand Down
12 changes: 8 additions & 4 deletions content/media/MediaDecoder.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class MediaDecoder : public nsIObserver,

virtual void NotifyWaitingForResourcesStatusChanged() MOZ_OVERRIDE;

void SetPlaybackRate(double aPlaybackRate);
virtual void SetPlaybackRate(double aPlaybackRate);
void SetPreservesPitch(bool aPreservesPitch);

// Directs the decoder to not preroll extra samples until the media is
Expand Down Expand Up @@ -760,7 +760,7 @@ class MediaDecoder : public nsIObserver,
// Change to a new play state. This updates the mState variable and
// notifies any thread blocking on this object's monitor of the
// change. Call on the main thread only.
void ChangeState(PlayState aState);
virtual void ChangeState(PlayState aState);

// Called by |ChangeState|, to update the state machine.
// Call on the main thread only and the lock must be obtained.
Expand All @@ -772,7 +772,11 @@ class MediaDecoder : public nsIObserver,

// Called when the metadata from the media file has been loaded by the
// state machine. Call on the main thread only.
void MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags);
virtual void MetadataLoaded(int aChannels,
int aRate,
bool aHasAudio,
bool aHasVideo,
MetadataTags* aTags);

// Called when the first frame has been loaded.
// Call on the main thread only.
Expand Down Expand Up @@ -805,7 +809,7 @@ class MediaDecoder : public nsIObserver,

// Calls mElement->UpdateReadyStateForData, telling it whether we have
// data for the next frame and if we're buffering. Main thread only.
void UpdateReadyStateForData();
virtual void UpdateReadyStateForData();

// Find the end of the cached data starting at the current decoder
// position.
Expand Down
72 changes: 72 additions & 0 deletions content/media/omx/AudioOffloadPlayerBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/*
* Copyright (c) 2014 The Linux Foundation. All rights reserved.
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef AUDIO_OFFLOAD_PLAYER_BASE_H_
#define AUDIO_OFFLOAD_PLAYER_BASE_H_

#include "MediaDecoderOwner.h"
#include "MediaOmxDecoder.h"

namespace mozilla {

class MediaOmxDecoder;

/**
* AudioOffloadPlayer interface class which has funtions used by MediaOmxDecoder
* This is to reduce the dependency of AudioOffloadPlayer in MediaOmxDecoder
*/
class AudioOffloadPlayerBase
{
typedef android::status_t status_t;
typedef android::MediaSource MediaSource;

public:
virtual ~AudioOffloadPlayerBase() {};

// Caller retains ownership of "aSource".
virtual void SetSource(const android::sp<MediaSource> &aSource) {}

// Start the source if it's not already started and open the AudioSink to
// create an offloaded audio track
virtual status_t Start(bool aSourceAlreadyStarted = false)
{
return android::NO_INIT;
}

virtual void ChangeState(MediaDecoder::PlayState aState) {}

virtual void SetVolume(double aVolume) {}

virtual double GetMediaTimeSecs() { return 0; }

// To update progress bar when the element is visible
virtual void SetElementVisibility(bool aIsVisible) {}

// Update ready state based on current play state. Not checking data
// availability since offloading is currently done only when whole compressed
// data is available
virtual MediaDecoderOwner::NextFrameStatus GetNextFrameStatus()
{
return MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE;
}
};

} // namespace mozilla

#endif // AUDIO_OFFLOAD_PLAYER_BASE_H_
Loading

0 comments on commit 27518df

Please sign in to comment.