content/media/fmp4/MP4Reader.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #if !defined(MP4Reader_h_)
michael@0 8 #define MP4Reader_h_
michael@0 9
michael@0 10 #include "MediaDecoderReader.h"
michael@0 11 #include "nsAutoPtr.h"
michael@0 12 #include "PlatformDecoderModule.h"
michael@0 13 #include "mp4_demuxer/mp4_demuxer.h"
michael@0 14 #include "mp4_demuxer/box_definitions.h"
michael@0 15 #include "MediaTaskQueue.h"
michael@0 16
michael@0 17 #include <deque>
michael@0 18 #include "mozilla/Monitor.h"
michael@0 19
michael@0 20 namespace mozilla {
michael@0 21
michael@0 22 namespace dom {
michael@0 23 class TimeRanges;
michael@0 24 }
michael@0 25
michael@0 26 typedef std::deque<mp4_demuxer::MP4Sample*> MP4SampleQueue;
michael@0 27
michael@0 28 class MP4Stream;
michael@0 29
michael@0 30 class MP4Reader : public MediaDecoderReader
michael@0 31 {
michael@0 32 public:
michael@0 33 MP4Reader(AbstractMediaDecoder* aDecoder);
michael@0 34
michael@0 35 virtual ~MP4Reader();
michael@0 36
michael@0 37 virtual nsresult Init(MediaDecoderReader* aCloneDonor) MOZ_OVERRIDE;
michael@0 38
michael@0 39 virtual bool DecodeAudioData() MOZ_OVERRIDE;
michael@0 40 virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
michael@0 41 int64_t aTimeThreshold) MOZ_OVERRIDE;
michael@0 42
michael@0 43 virtual bool HasAudio() MOZ_OVERRIDE;
michael@0 44 virtual bool HasVideo() MOZ_OVERRIDE;
michael@0 45
michael@0 46 virtual nsresult ReadMetadata(MediaInfo* aInfo,
michael@0 47 MetadataTags** aTags) MOZ_OVERRIDE;
michael@0 48
michael@0 49 virtual nsresult Seek(int64_t aTime,
michael@0 50 int64_t aStartTime,
michael@0 51 int64_t aEndTime,
michael@0 52 int64_t aCurrentTime) MOZ_OVERRIDE;
michael@0 53 private:
michael@0 54
michael@0 55 // Destroys all decoder resources.
michael@0 56 void Shutdown();
michael@0 57
michael@0 58 // Initializes mLayersBackendType if possible.
michael@0 59 void InitLayersBackendType();
michael@0 60
michael@0 61 // Blocks until the demuxer produces an sample of specified type.
michael@0 62 // Returns nullptr on error on EOS. Caller must delete sample.
michael@0 63 mp4_demuxer::MP4Sample* PopSample(mp4_demuxer::TrackType aTrack);
michael@0 64
michael@0 65 bool SkipVideoDemuxToNextKeyFrame(int64_t aTimeThreshold, uint32_t& parsed);
michael@0 66
michael@0 67 void Output(mp4_demuxer::TrackType aType, MediaData* aSample);
michael@0 68 void InputExhausted(mp4_demuxer::TrackType aTrack);
michael@0 69 void Error(mp4_demuxer::TrackType aTrack);
michael@0 70 bool Decode(mp4_demuxer::TrackType aTrack);
michael@0 71 void Flush(mp4_demuxer::TrackType aTrack);
michael@0 72
michael@0 73 nsAutoPtr<mp4_demuxer::MP4Demuxer> mDemuxer;
michael@0 74 nsAutoPtr<MP4Stream> mMP4Stream;
michael@0 75 nsAutoPtr<PlatformDecoderModule> mPlatform;
michael@0 76
michael@0 77 class DecoderCallback : public MediaDataDecoderCallback {
michael@0 78 public:
michael@0 79 DecoderCallback(MP4Reader* aReader,
michael@0 80 mp4_demuxer::TrackType aType)
michael@0 81 : mReader(aReader)
michael@0 82 , mType(aType)
michael@0 83 {
michael@0 84 }
michael@0 85 virtual void Output(MediaData* aSample) MOZ_OVERRIDE {
michael@0 86 mReader->Output(mType, aSample);
michael@0 87 }
michael@0 88 virtual void InputExhausted() MOZ_OVERRIDE {
michael@0 89 mReader->InputExhausted(mType);
michael@0 90 }
michael@0 91 virtual void Error() MOZ_OVERRIDE {
michael@0 92 mReader->Error(mType);
michael@0 93 }
michael@0 94 private:
michael@0 95 MP4Reader* mReader;
michael@0 96 mp4_demuxer::TrackType mType;
michael@0 97 };
michael@0 98
michael@0 99 struct DecoderData {
michael@0 100 DecoderData(const char* aMonitorName,
michael@0 101 uint32_t aDecodeAhead)
michael@0 102 : mMonitor(aMonitorName)
michael@0 103 , mNumSamplesInput(0)
michael@0 104 , mNumSamplesOutput(0)
michael@0 105 , mDecodeAhead(aDecodeAhead)
michael@0 106 , mActive(false)
michael@0 107 , mInputExhausted(false)
michael@0 108 , mError(false)
michael@0 109 , mIsFlushing(false)
michael@0 110 {
michael@0 111 }
michael@0 112
michael@0 113 // The platform decoder.
michael@0 114 RefPtr<MediaDataDecoder> mDecoder;
michael@0 115 // Queue of input extracted by the demuxer, but not yet sent to the
michael@0 116 // platform decoder.
michael@0 117 MP4SampleQueue mDemuxedSamples;
michael@0 118 // TaskQueue on which decoder can choose to decode.
michael@0 119 // Only non-null up until the decoder is created.
michael@0 120 RefPtr<MediaTaskQueue> mTaskQueue;
michael@0 121 // Callback that receives output and error notifications from the decoder.
michael@0 122 nsAutoPtr<DecoderCallback> mCallback;
michael@0 123 // Monitor that protects all non-threadsafe state; the primitives
michael@0 124 // that follow.
michael@0 125 Monitor mMonitor;
michael@0 126 uint64_t mNumSamplesInput;
michael@0 127 uint64_t mNumSamplesOutput;
michael@0 128 uint32_t mDecodeAhead;
michael@0 129 // Whether this stream exists in the media.
michael@0 130 bool mActive;
michael@0 131 bool mInputExhausted;
michael@0 132 bool mError;
michael@0 133 bool mIsFlushing;
michael@0 134 };
michael@0 135 DecoderData mAudio;
michael@0 136 DecoderData mVideo;
michael@0 137
michael@0 138 // The last number of decoded output frames that we've reported to
michael@0 139 // MediaDecoder::NotifyDecoded(). We diff the number of output video
michael@0 140 // frames every time that DecodeVideoData() is called, and report the
michael@0 141 // delta there.
michael@0 142 uint64_t mLastReportedNumDecodedFrames;
michael@0 143
michael@0 144 DecoderData& GetDecoderData(mp4_demuxer::TrackType aTrack);
michael@0 145 MP4SampleQueue& SampleQueue(mp4_demuxer::TrackType aTrack);
michael@0 146 MediaDataDecoder* Decoder(mp4_demuxer::TrackType aTrack);
michael@0 147
michael@0 148 layers::LayersBackend mLayersBackendType;
michael@0 149
michael@0 150 };
michael@0 151
michael@0 152 } // namespace mozilla
michael@0 153
michael@0 154 #endif

mercurial