content/media/mediasource/SubBufferDecoder.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: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 #ifndef MOZILLA_SUBBUFFERDECODER_H_
michael@0 8 #define MOZILLA_SUBBUFFERDECODER_H_
michael@0 9
michael@0 10 #include "BufferDecoder.h"
michael@0 11 #include "SourceBufferResource.h"
michael@0 12
michael@0 13 namespace mozilla {
michael@0 14
michael@0 15 class MediaSourceDecoder;
michael@0 16
michael@0 17 class SubBufferDecoder : public BufferDecoder
michael@0 18 {
michael@0 19 public:
michael@0 20 // This class holds a weak pointer to MediaResource. It's the responsibility
michael@0 21 // of the caller to manage the memory of the MediaResource object.
michael@0 22 SubBufferDecoder(MediaResource* aResource, MediaSourceDecoder* aParentDecoder)
michael@0 23 : BufferDecoder(aResource), mParentDecoder(aParentDecoder), mReader(nullptr)
michael@0 24 {
michael@0 25 }
michael@0 26
michael@0 27 void SetReader(MediaDecoderReader* aReader)
michael@0 28 {
michael@0 29 MOZ_ASSERT(!mReader);
michael@0 30 mReader = aReader;
michael@0 31 }
michael@0 32
michael@0 33 MediaDecoderReader* GetReader()
michael@0 34 {
michael@0 35 return mReader;
michael@0 36 }
michael@0 37
michael@0 38 virtual ReentrantMonitor& GetReentrantMonitor() MOZ_OVERRIDE;
michael@0 39 virtual bool OnStateMachineThread() const MOZ_OVERRIDE;
michael@0 40 virtual bool OnDecodeThread() const MOZ_OVERRIDE;
michael@0 41 virtual SourceBufferResource* GetResource() const MOZ_OVERRIDE;
michael@0 42 virtual void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
michael@0 43 virtual void UpdateEstimatedMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
michael@0 44 virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE;
michael@0 45 virtual void SetTransportSeekable(bool aTransportSeekable) MOZ_OVERRIDE;
michael@0 46 virtual layers::ImageContainer* GetImageContainer() MOZ_OVERRIDE;
michael@0 47 virtual MediaDecoderOwner* GetOwner() MOZ_OVERRIDE;
michael@0 48
michael@0 49 void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset)
michael@0 50 {
michael@0 51 mReader->NotifyDataArrived(aBuffer, aLength, aOffset);
michael@0 52
michael@0 53 // XXX: Params make no sense to parent decoder as it relates to a
michael@0 54 // specific SubBufferDecoder's data stream. Pass bogus values here to
michael@0 55 // force parent decoder's state machine to recompute end time for
michael@0 56 // infinite length media.
michael@0 57 mParentDecoder->NotifyDataArrived(nullptr, 0, 0);
michael@0 58 }
michael@0 59
michael@0 60 nsresult GetBuffered(dom::TimeRanges* aBuffered)
michael@0 61 {
michael@0 62 // XXX: Need mStartTime (from StateMachine) instead of passing 0.
michael@0 63 return mReader->GetBuffered(aBuffered, 0);
michael@0 64 }
michael@0 65
michael@0 66 // Given a time convert it into an approximate byte offset from the
michael@0 67 // cached data. Returns -1 if no such value is computable.
michael@0 68 int64_t ConvertToByteOffset(double aTime);
michael@0 69
michael@0 70 int64_t GetMediaDuration() MOZ_OVERRIDE
michael@0 71 {
michael@0 72 return mMediaDuration;
michael@0 73 }
michael@0 74
michael@0 75 private:
michael@0 76 MediaSourceDecoder* mParentDecoder;
michael@0 77 nsAutoPtr<MediaDecoderReader> mReader;
michael@0 78 int64_t mMediaDuration;
michael@0 79 };
michael@0 80
michael@0 81 } // namespace mozilla
michael@0 82
michael@0 83 #endif /* MOZILLA_SUBBUFFERDECODER_H_ */

mercurial