content/media/mediasource/SubBufferDecoder.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/mediasource/SubBufferDecoder.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef MOZILLA_SUBBUFFERDECODER_H_
    1.11 +#define MOZILLA_SUBBUFFERDECODER_H_
    1.12 +
    1.13 +#include "BufferDecoder.h"
    1.14 +#include "SourceBufferResource.h"
    1.15 +
    1.16 +namespace mozilla {
    1.17 +
    1.18 +class MediaSourceDecoder;
    1.19 +
    1.20 +class SubBufferDecoder : public BufferDecoder
    1.21 +{
    1.22 +public:
    1.23 +  // This class holds a weak pointer to MediaResource.  It's the responsibility
    1.24 +  // of the caller to manage the memory of the MediaResource object.
    1.25 +  SubBufferDecoder(MediaResource* aResource, MediaSourceDecoder* aParentDecoder)
    1.26 +    : BufferDecoder(aResource), mParentDecoder(aParentDecoder), mReader(nullptr)
    1.27 +  {
    1.28 +  }
    1.29 +
    1.30 +  void SetReader(MediaDecoderReader* aReader)
    1.31 +  {
    1.32 +    MOZ_ASSERT(!mReader);
    1.33 +    mReader = aReader;
    1.34 +  }
    1.35 +
    1.36 +  MediaDecoderReader* GetReader()
    1.37 +  {
    1.38 +    return mReader;
    1.39 +  }
    1.40 +
    1.41 +  virtual ReentrantMonitor& GetReentrantMonitor() MOZ_OVERRIDE;
    1.42 +  virtual bool OnStateMachineThread() const MOZ_OVERRIDE;
    1.43 +  virtual bool OnDecodeThread() const MOZ_OVERRIDE;
    1.44 +  virtual SourceBufferResource* GetResource() const MOZ_OVERRIDE;
    1.45 +  virtual void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
    1.46 +  virtual void UpdateEstimatedMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
    1.47 +  virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE;
    1.48 +  virtual void SetTransportSeekable(bool aTransportSeekable) MOZ_OVERRIDE;
    1.49 +  virtual layers::ImageContainer* GetImageContainer() MOZ_OVERRIDE;
    1.50 +  virtual MediaDecoderOwner* GetOwner() MOZ_OVERRIDE;
    1.51 +
    1.52 +  void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset)
    1.53 +  {
    1.54 +    mReader->NotifyDataArrived(aBuffer, aLength, aOffset);
    1.55 +
    1.56 +    // XXX: Params make no sense to parent decoder as it relates to a
    1.57 +    // specific SubBufferDecoder's data stream.  Pass bogus values here to
    1.58 +    // force parent decoder's state machine to recompute end time for
    1.59 +    // infinite length media.
    1.60 +    mParentDecoder->NotifyDataArrived(nullptr, 0, 0);
    1.61 +  }
    1.62 +
    1.63 +  nsresult GetBuffered(dom::TimeRanges* aBuffered)
    1.64 +  {
    1.65 +    // XXX: Need mStartTime (from StateMachine) instead of passing 0.
    1.66 +    return mReader->GetBuffered(aBuffered, 0);
    1.67 +  }
    1.68 +
    1.69 +  // Given a time convert it into an approximate byte offset from the
    1.70 +  // cached data. Returns -1 if no such value is computable.
    1.71 +  int64_t ConvertToByteOffset(double aTime);
    1.72 +
    1.73 +  int64_t GetMediaDuration() MOZ_OVERRIDE
    1.74 +  {
    1.75 +    return mMediaDuration;
    1.76 +  }
    1.77 +
    1.78 +private:
    1.79 +  MediaSourceDecoder* mParentDecoder;
    1.80 +  nsAutoPtr<MediaDecoderReader> mReader;
    1.81 +  int64_t mMediaDuration;
    1.82 +};
    1.83 +
    1.84 +} // namespace mozilla
    1.85 +
    1.86 +#endif /* MOZILLA_SUBBUFFERDECODER_H_ */

mercurial