2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
#ifndef MEDIA_BASE_MEDIA_STREAM_H_
|
|
|
|
#define MEDIA_BASE_MEDIA_STREAM_H_
|
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/memory/ref_counted.h"
|
|
|
|
#include "packager/base/memory/scoped_ptr.h"
|
|
|
|
#include "packager/media/base/status.h"
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-10-11 21:44:55 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class Demuxer;
|
|
|
|
class Muxer;
|
|
|
|
class MediaSample;
|
|
|
|
class StreamInfo;
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// MediaStream connects Demuxer to Muxer. It is an abstraction for a media
|
|
|
|
/// elementary stream.
|
2013-10-11 21:44:55 +00:00
|
|
|
class MediaStream {
|
|
|
|
public:
|
|
|
|
enum MediaStreamOperation {
|
|
|
|
kPush,
|
|
|
|
kPull,
|
|
|
|
};
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Create MediaStream from StreamInfo and Demuxer.
|
|
|
|
/// @param demuxer cannot be NULL.
|
2013-10-11 21:44:55 +00:00
|
|
|
MediaStream(scoped_refptr<StreamInfo> info, Demuxer* demuxer);
|
|
|
|
~MediaStream();
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Connect the stream to Muxer.
|
|
|
|
/// @param muxer cannot be NULL.
|
2013-10-11 21:44:55 +00:00
|
|
|
void Connect(Muxer* muxer);
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Start the stream for pushing or pulling.
|
2013-10-11 21:44:55 +00:00
|
|
|
Status Start(MediaStreamOperation operation);
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Push sample to Muxer (triggered by Demuxer).
|
2013-10-11 21:44:55 +00:00
|
|
|
Status PushSample(const scoped_refptr<MediaSample>& sample);
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Pull sample from Demuxer (triggered by Muxer).
|
2013-10-11 21:44:55 +00:00
|
|
|
Status PullSample(scoped_refptr<MediaSample>* sample);
|
|
|
|
|
2013-11-12 20:32:44 +00:00
|
|
|
Demuxer* demuxer() { return demuxer_; }
|
|
|
|
Muxer* muxer() { return muxer_; }
|
|
|
|
const scoped_refptr<StreamInfo> info() const;
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// @return a human-readable string describing |*this|.
|
2013-10-11 21:44:55 +00:00
|
|
|
std::string ToString() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// State transition diagram available @ http://goo.gl/ThJQbl.
|
|
|
|
enum State {
|
|
|
|
kIdle,
|
|
|
|
kConnected,
|
|
|
|
kDisconnected,
|
|
|
|
kPushing,
|
|
|
|
kPulling,
|
|
|
|
};
|
|
|
|
|
|
|
|
scoped_refptr<StreamInfo> info_;
|
|
|
|
Demuxer* demuxer_;
|
|
|
|
Muxer* muxer_;
|
|
|
|
State state_;
|
|
|
|
// An internal buffer to store samples temporarily.
|
|
|
|
std::deque<scoped_refptr<MediaSample> > samples_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MediaStream);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_BASE_MEDIA_STREAM_H_
|