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>
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#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.
|
2017-01-24 00:55:02 +00:00
|
|
|
MediaStream(std::shared_ptr<StreamInfo> info, Demuxer* demuxer);
|
2013-10-11 21:44:55 +00:00
|
|
|
~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).
|
2017-01-24 00:55:02 +00:00
|
|
|
Status PushSample(const std::shared_ptr<MediaSample>& sample);
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Pull sample from Demuxer (triggered by Muxer).
|
2017-01-24 00:55:02 +00:00
|
|
|
Status PullSample(std::shared_ptr<MediaSample>* sample);
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2013-11-12 20:32:44 +00:00
|
|
|
Demuxer* demuxer() { return demuxer_; }
|
|
|
|
Muxer* muxer() { return muxer_; }
|
2017-01-24 00:55:02 +00:00
|
|
|
const std::shared_ptr<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:
|
2017-01-24 00:55:02 +00:00
|
|
|
MediaStream(const MediaStream&) = delete;
|
|
|
|
MediaStream& operator=(const MediaStream&) = delete;
|
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
// State transition diagram available @ http://goo.gl/ThJQbl.
|
|
|
|
enum State {
|
|
|
|
kIdle,
|
|
|
|
kConnected,
|
|
|
|
kDisconnected,
|
|
|
|
kPushing,
|
|
|
|
kPulling,
|
|
|
|
};
|
|
|
|
|
2017-01-24 00:55:02 +00:00
|
|
|
std::shared_ptr<StreamInfo> info_;
|
2013-10-11 21:44:55 +00:00
|
|
|
Demuxer* demuxer_;
|
|
|
|
Muxer* muxer_;
|
|
|
|
State state_;
|
|
|
|
// An internal buffer to store samples temporarily.
|
2017-01-24 00:55:02 +00:00
|
|
|
std::deque<std::shared_ptr<MediaSample>> samples_;
|
2013-10-11 21:44:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // 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_
|