2012-09-27 04:33:43 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-11-14 19:46:40 +00:00
|
|
|
#if !defined(MediaOmxReader_h_)
|
|
|
|
#define MediaOmxReader_h_
|
2012-09-27 04:33:43 +00:00
|
|
|
|
2014-08-14 03:38:21 +00:00
|
|
|
#include "MediaOmxCommonReader.h"
|
2012-09-27 04:33:43 +00:00
|
|
|
#include "MediaResource.h"
|
2012-11-14 19:46:40 +00:00
|
|
|
#include "MediaDecoderReader.h"
|
2014-09-15 09:08:48 +00:00
|
|
|
#include "nsMimeTypes.h"
|
|
|
|
#include "MP3FrameParser.h"
|
2013-09-05 20:25:17 +00:00
|
|
|
#include "nsRect.h"
|
2013-05-02 16:56:09 +00:00
|
|
|
#include <ui/GraphicBuffer.h>
|
2014-04-08 15:29:07 +00:00
|
|
|
#include <stagefright/MediaSource.h>
|
2012-09-27 04:33:43 +00:00
|
|
|
|
2013-02-01 22:13:23 +00:00
|
|
|
namespace android {
|
|
|
|
class OmxDecoder;
|
2014-05-06 05:26:46 +00:00
|
|
|
class MOZ_EXPORT MediaExtractor;
|
2013-02-01 22:13:23 +00:00
|
|
|
}
|
2012-09-27 04:33:43 +00:00
|
|
|
|
2012-11-14 19:45:33 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
2013-03-02 19:14:44 +00:00
|
|
|
namespace dom {
|
|
|
|
class TimeRanges;
|
|
|
|
}
|
|
|
|
|
2012-11-19 15:11:21 +00:00
|
|
|
class AbstractMediaDecoder;
|
|
|
|
|
2014-08-14 03:38:21 +00:00
|
|
|
class MediaOmxReader : public MediaOmxCommonReader
|
2012-09-27 04:33:43 +00:00
|
|
|
{
|
2014-10-02 03:46:49 +00:00
|
|
|
// This flag protect the mIsShutdown variable, that may access by decoder / main / IO thread.
|
|
|
|
Mutex mMutex;
|
2012-09-27 04:33:43 +00:00
|
|
|
nsCString mType;
|
|
|
|
bool mHasVideo;
|
|
|
|
bool mHasAudio;
|
|
|
|
nsIntRect mPicture;
|
|
|
|
nsIntSize mInitialFrame;
|
|
|
|
int64_t mVideoSeekTimeUs;
|
|
|
|
int64_t mAudioSeekTimeUs;
|
2014-09-15 09:08:48 +00:00
|
|
|
int64_t mLastParserDuration;
|
2012-11-27 04:08:40 +00:00
|
|
|
int32_t mSkipCount;
|
2014-09-15 09:08:48 +00:00
|
|
|
bool mUseParserDuration;
|
2014-10-02 03:46:49 +00:00
|
|
|
bool mIsShutdown;
|
2013-09-23 09:53:36 +00:00
|
|
|
protected:
|
|
|
|
android::sp<android::OmxDecoder> mOmxDecoder;
|
2014-01-22 15:50:23 +00:00
|
|
|
android::sp<android::MediaExtractor> mExtractor;
|
2014-09-15 09:08:48 +00:00
|
|
|
MP3FrameParser mMP3FrameParser;
|
2014-10-06 03:03:14 +00:00
|
|
|
|
|
|
|
// A cache value updated by UpdateIsWaitingMediaResources(), makes the
|
|
|
|
// "waiting resources state" is synchronous to StateMachine.
|
|
|
|
bool mIsWaitingResources;
|
|
|
|
|
2013-09-23 09:53:36 +00:00
|
|
|
// Called by ReadMetadata() during MediaDecoderStateMachine::DecodeMetadata()
|
|
|
|
// on decode thread. It create and initialize the OMX decoder including
|
|
|
|
// setting up custom extractor. The extractor provide the essential
|
|
|
|
// information used for creating OMX decoder such as video/audio codec.
|
|
|
|
virtual nsresult InitOmxDecoder();
|
|
|
|
|
2014-05-19 02:23:00 +00:00
|
|
|
// Called inside DecodeVideoFrame, DecodeAudioData, ReadMetadata and Seek
|
|
|
|
// to activate the decoder automatically.
|
|
|
|
virtual void EnsureActive();
|
|
|
|
|
2014-10-06 03:03:14 +00:00
|
|
|
// Check the underlying HW resources are available and store the result in
|
|
|
|
// mIsWaitingResources. The result might be changed by binder thread,
|
|
|
|
// Can only called by ReadMetadata.
|
|
|
|
void UpdateIsWaitingMediaResources();
|
|
|
|
|
2012-09-27 04:33:43 +00:00
|
|
|
public:
|
2012-11-19 15:11:21 +00:00
|
|
|
MediaOmxReader(AbstractMediaDecoder* aDecoder);
|
2012-11-14 19:46:40 +00:00
|
|
|
~MediaOmxReader();
|
2012-09-27 04:33:43 +00:00
|
|
|
|
2012-11-14 19:46:40 +00:00
|
|
|
virtual nsresult Init(MediaDecoderReader* aCloneDonor);
|
2012-09-27 04:33:43 +00:00
|
|
|
|
2013-01-24 12:38:32 +00:00
|
|
|
virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset);
|
|
|
|
|
2012-09-27 04:33:43 +00:00
|
|
|
virtual bool DecodeAudioData();
|
|
|
|
virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
|
|
|
|
int64_t aTimeThreshold);
|
|
|
|
|
|
|
|
virtual bool HasAudio()
|
|
|
|
{
|
|
|
|
return mHasAudio;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool HasVideo()
|
|
|
|
{
|
|
|
|
return mHasVideo;
|
|
|
|
}
|
|
|
|
|
2014-10-06 03:03:14 +00:00
|
|
|
// Return mIsWaitingResources.
|
|
|
|
virtual bool IsWaitingMediaResources() MOZ_OVERRIDE;
|
2013-06-10 12:22:05 +00:00
|
|
|
|
|
|
|
virtual bool IsDormantNeeded();
|
|
|
|
virtual void ReleaseMediaResources();
|
|
|
|
|
2014-10-06 03:03:14 +00:00
|
|
|
virtual void PreReadMetadata() MOZ_OVERRIDE;
|
2013-09-27 05:22:38 +00:00
|
|
|
virtual nsresult ReadMetadata(MediaInfo* aInfo,
|
2012-11-09 00:40:08 +00:00
|
|
|
MetadataTags** aTags);
|
2014-12-16 09:52:57 +00:00
|
|
|
virtual nsRefPtr<SeekPromise>
|
2015-01-16 18:57:59 +00:00
|
|
|
Seek(int64_t aTime, int64_t aEndTime) MOZ_OVERRIDE;
|
2013-04-11 00:58:25 +00:00
|
|
|
|
2014-06-23 10:08:34 +00:00
|
|
|
virtual bool IsMediaSeekable() MOZ_OVERRIDE;
|
|
|
|
|
2014-03-11 03:44:10 +00:00
|
|
|
virtual void SetIdle() MOZ_OVERRIDE;
|
2013-04-11 00:58:25 +00:00
|
|
|
|
2014-12-09 19:43:21 +00:00
|
|
|
virtual nsRefPtr<ShutdownPromise> Shutdown() MOZ_OVERRIDE;
|
2014-06-18 05:07:02 +00:00
|
|
|
|
2014-10-02 03:46:49 +00:00
|
|
|
bool IsShutdown() {
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
return mIsShutdown;
|
|
|
|
}
|
|
|
|
|
2014-07-02 23:55:00 +00:00
|
|
|
void ReleaseDecoder();
|
2014-08-14 03:38:21 +00:00
|
|
|
|
2014-09-15 09:08:48 +00:00
|
|
|
int64_t ProcessCachedData(int64_t aOffset, bool aWaitForCompletion);
|
|
|
|
|
2014-10-02 03:46:49 +00:00
|
|
|
void CancelProcessCachedData();
|
|
|
|
|
2014-08-14 03:38:21 +00:00
|
|
|
android::sp<android::MediaSource> GetAudioOffloadTrack();
|
2012-09-27 04:33:43 +00:00
|
|
|
};
|
|
|
|
|
2012-11-14 19:45:33 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-09-27 04:33:43 +00:00
|
|
|
#endif
|