2012-11-19 19:11:21 +04: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/. */
|
|
|
|
|
|
|
|
#ifndef AbstractMediaDecoder_h_
|
|
|
|
#define AbstractMediaDecoder_h_
|
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2015-07-16 21:52:43 +03:00
|
|
|
#include "mozilla/StateMirroring.h"
|
|
|
|
|
2016-07-18 03:41:40 +03:00
|
|
|
#include "FrameStatistics.h"
|
2015-11-18 04:00:56 +03:00
|
|
|
#include "MediaEventSource.h"
|
2014-07-04 07:54:54 +04:00
|
|
|
#include "MediaInfo.h"
|
2012-11-19 19:11:21 +04:00
|
|
|
#include "nsISupports.h"
|
2012-11-30 17:17:54 +04:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2012-11-19 19:11:21 +04:00
|
|
|
|
|
|
|
namespace mozilla
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace layers
|
|
|
|
{
|
|
|
|
class ImageContainer;
|
2016-11-08 05:23:12 +03:00
|
|
|
class KnowsCompositor;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
2012-11-19 19:11:21 +04:00
|
|
|
class MediaResource;
|
|
|
|
class ReentrantMonitor;
|
|
|
|
class VideoFrameContainer;
|
2013-05-04 14:12:41 +04:00
|
|
|
class MediaDecoderOwner;
|
2014-07-30 10:53:34 +04:00
|
|
|
class CDMProxy;
|
2016-11-16 01:35:36 +03:00
|
|
|
class GMPCrashHelper;
|
2012-11-30 17:17:54 +04:00
|
|
|
|
|
|
|
typedef nsDataHashtable<nsCStringHashKey, nsCString> MetadataTags;
|
2012-11-19 19:11:21 +04:00
|
|
|
|
2013-02-02 02:13:23 +04:00
|
|
|
static inline bool IsCurrentThread(nsIThread* aThread) {
|
|
|
|
return NS_GetCurrentThread() == aThread;
|
|
|
|
}
|
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
/**
|
|
|
|
* The AbstractMediaDecoder class describes the public interface for a media decoder
|
|
|
|
* and is used by the MediaReader classes.
|
|
|
|
*/
|
2015-06-11 08:55:20 +03:00
|
|
|
class AbstractMediaDecoder : public nsIObserver
|
2012-11-19 19:11:21 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-06-30 00:27:16 +03:00
|
|
|
// A special version of the above for the ogg decoder that is allowed to be
|
|
|
|
// called cross-thread.
|
|
|
|
virtual bool IsOggDecoderShutdown() { return false; }
|
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
// Get the current MediaResource being used. Its URI will be returned
|
|
|
|
// by currentSrc. Returns what was passed to Load(), if Load() has been called.
|
|
|
|
virtual MediaResource* GetResource() const = 0;
|
|
|
|
|
2015-03-03 07:46:48 +03:00
|
|
|
// Increments the parsed, decoded and dropped frame counters by the passed in
|
|
|
|
// counts.
|
2012-11-19 19:11:21 +04:00
|
|
|
// Can be called on any thread.
|
2016-07-18 03:41:40 +03:00
|
|
|
virtual void NotifyDecodedFrames(const FrameStatisticsData& aStats) = 0;
|
2012-11-19 19:11:21 +04:00
|
|
|
|
2015-06-09 22:41:24 +03:00
|
|
|
virtual AbstractCanonical<media::NullableTimeUnit>* CanonicalDurationOrNull() { return nullptr; };
|
2012-11-19 19:11:21 +04:00
|
|
|
|
2015-11-18 04:00:56 +03:00
|
|
|
// Return an event that will be notified when data arrives in MediaResource.
|
|
|
|
// MediaDecoderReader will register with this event to receive notifications
|
2016-04-12 10:00:29 +03:00
|
|
|
// in order to update buffer ranges.
|
2015-11-18 04:00:56 +03:00
|
|
|
// Return null if this decoder doesn't support the event.
|
|
|
|
virtual MediaEventSource<void>* DataArrivedEvent()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-11-08 05:23:12 +03:00
|
|
|
// Returns an event that will be notified when the owning document changes state
|
|
|
|
// and we might have a new compositor. If this new compositor requires us to
|
|
|
|
// recreate our decoders, then we expect the existing decoderis to return an
|
|
|
|
// error independently of this.
|
|
|
|
virtual MediaEventSource<RefPtr<layers::KnowsCompositor>>* CompositorUpdatedEvent()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-08-21 23:51:01 +03:00
|
|
|
// Notify the media decoder that a decryption key is required before emitting
|
|
|
|
// further output. This only needs to be overridden for decoders that expect
|
|
|
|
// encryption, such as the MediaSource decoder.
|
|
|
|
virtual void NotifyWaitingForKey() {}
|
|
|
|
|
|
|
|
// Return an event that will be notified when a decoder is waiting for a
|
|
|
|
// decryption key before it can return more output.
|
|
|
|
virtual MediaEventSource<void>* WaitingForKeyEvent()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-06-17 02:11:06 +03:00
|
|
|
protected:
|
|
|
|
virtual void UpdateEstimatedMediaDuration(int64_t aDuration) {};
|
|
|
|
public:
|
|
|
|
void DispatchUpdateEstimatedMediaDuration(int64_t aDuration)
|
|
|
|
{
|
2016-05-05 11:45:00 +03:00
|
|
|
NS_DispatchToMainThread(NewRunnableMethod<int64_t>(this,
|
|
|
|
&AbstractMediaDecoder::UpdateEstimatedMediaDuration,
|
|
|
|
aDuration));
|
2015-06-17 02:11:06 +03:00
|
|
|
}
|
2013-05-03 11:48:37 +04:00
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
virtual VideoFrameContainer* GetVideoFrameContainer() = 0;
|
|
|
|
virtual mozilla::layers::ImageContainer* GetImageContainer() = 0;
|
|
|
|
|
2016-07-27 05:26:21 +03:00
|
|
|
// Returns the owner of this decoder or null when the decoder is shutting
|
|
|
|
// down. The owner should only be used on the main thread.
|
2016-07-28 12:21:09 +03:00
|
|
|
virtual MediaDecoderOwner* GetOwner() const = 0;
|
2013-05-04 14:12:41 +04:00
|
|
|
|
2014-08-18 16:49:51 +04:00
|
|
|
// Set by Reader if the current audio track can be offloaded
|
|
|
|
virtual void SetPlatformCanOffloadAudio(bool aCanOffloadAudio) {}
|
|
|
|
|
2016-06-29 02:42:07 +03:00
|
|
|
virtual already_AddRefed<GMPCrashHelper> GetCrashHelper() { return nullptr; }
|
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
// 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.
|
|
|
|
class AutoNotifyDecoded {
|
|
|
|
public:
|
2015-03-03 07:46:46 +03:00
|
|
|
explicit AutoNotifyDecoded(AbstractMediaDecoder* aDecoder)
|
2016-07-18 03:41:40 +03:00
|
|
|
: mDecoder(aDecoder)
|
|
|
|
{}
|
2012-11-19 19:11:21 +04:00
|
|
|
~AutoNotifyDecoded() {
|
2015-01-11 23:41:50 +03:00
|
|
|
if (mDecoder) {
|
2016-07-18 03:41:40 +03:00
|
|
|
mDecoder->NotifyDecodedFrames(mStats);
|
2015-01-11 23:41:50 +03:00
|
|
|
}
|
2012-11-19 19:11:21 +04:00
|
|
|
}
|
2016-07-18 03:41:40 +03:00
|
|
|
|
|
|
|
FrameStatisticsData mStats;
|
2015-03-03 07:46:46 +03:00
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
private:
|
|
|
|
AbstractMediaDecoder* mDecoder;
|
|
|
|
};
|
2014-07-30 10:53:34 +04:00
|
|
|
|
2015-06-11 08:55:20 +03:00
|
|
|
// Classes directly inheriting from AbstractMediaDecoder do not support
|
|
|
|
// Observe and it should never be called directly.
|
|
|
|
NS_IMETHOD Observe(nsISupports *aSubject, const char * aTopic, const char16_t * aData) override
|
|
|
|
{ MOZ_CRASH("Forbidden method"); return NS_OK; }
|
2012-11-19 19:11:21 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2012-11-19 19:11:21 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|