author JW Wang <>
Sun, 19 Jul 2015 21:25:08 +0800
changeset 287943 3ae3c45db961997a182616416097a8c49c6e9742
parent 286904 81beff07c6dc8176f2d78d443a716259fe6be924
child 288463 7115a03c413af932ac5d0821c853f474f5a6b438
permissions -rw-r--r--
Bug 1191170 - Move DecodedStreamData from the header to its source file. r=roc.

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 */

#ifndef DecodedStream_h_
#define DecodedStream_h_

#include "nsTArray.h"
#include "MediaInfo.h"

#include "mozilla/CheckedInt.h"
#include "mozilla/Maybe.h"
#include "mozilla/nsRefPtr.h"
#include "mozilla/ReentrantMonitor.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/gfx/Point.h"

namespace mozilla {

class DecodedStream;
class DecodedStreamData;
class MediaData;
class MediaInputPort;
class MediaStream;
class MediaStreamGraph;
class OutputStreamListener;
class ProcessedMediaStream;
class ReentrantMonitor;

template <class T> class MediaQueue;

namespace layers {
class Image;
} // namespace layers

class OutputStreamData {
  void Init(DecodedStream* aDecodedStream, ProcessedMediaStream* aStream);
  nsRefPtr<ProcessedMediaStream> mStream;
  // mPort connects DecodedStreamData::mStream to our mStream.
  nsRefPtr<MediaInputPort> mPort;
  nsRefPtr<OutputStreamListener> mListener;

class DecodedStream {
  DecodedStream(MediaQueue<MediaData>& aAudioQueue,
                MediaQueue<MediaData>& aVideoQueue);

  // Mimic MDSM::StartAudioThread.
  // Must be called before any calls to SendData().
  void StartPlayback(int64_t aStartTime, const MediaInfo& aInfo);
  // Mimic MDSM::StopAudioThread.
  void StopPlayback();

  void DestroyData();
  void RecreateData();
  void Connect(ProcessedMediaStream* aStream, bool aFinishWhenEnded);
  void Remove(MediaStream* aStream);
  void SetPlaying(bool aPlaying);
  int64_t AudioEndTime() const;
  int64_t GetPosition() const;
  bool IsFinished() const;
  bool HasConsumers() const;

  // Return true if stream is finished.
  bool SendData(double aVolume, bool aIsSameOrigin);

  virtual ~DecodedStream();

  ReentrantMonitor& GetReentrantMonitor() const;
  void RecreateData(MediaStreamGraph* aGraph);
  void Connect(OutputStreamData* aStream);
  nsTArray<OutputStreamData>& OutputStreams();
  void InitTracks();
  void AdvanceTracks();
  void SendAudio(double aVolume, bool aIsSameOrigin);
  void SendVideo(bool aIsSameOrigin);

  UniquePtr<DecodedStreamData> mData;
  // Data about MediaStreams that are being fed by the decoder.
  nsTArray<OutputStreamData> mOutputStreams;

  // TODO: This is a temp solution to get rid of decoder monitor on the main
  // thread in MDSM::AddOutputStream and MDSM::RecreateDecodedStream as
  // required by bug 1146482. DecodedStream needs to release monitor before
  // calling back into MDSM functions in order to prevent deadlocks.
  // Please move all capture-stream related code from MDSM into DecodedStream
  // and apply "dispatch + mirroring" to get rid of this monitor in the future.
  mutable ReentrantMonitor mMonitor;

  bool mPlaying;
  Maybe<int64_t> mStartTime;
  MediaInfo mInfo;

  MediaQueue<MediaData>& mAudioQueue;
  MediaQueue<MediaData>& mVideoQueue;

} // namespace mozilla

#endif // DecodedStream_h_