DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
media_stream.h
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef MEDIA_BASE_MEDIA_STREAM_H_
8 #define MEDIA_BASE_MEDIA_STREAM_H_
9 
10 #include <deque>
11 #include <memory>
12 
13 #include "packager/media/base/status.h"
14 
15 namespace shaka {
16 namespace media {
17 
18 class Demuxer;
19 class Muxer;
20 class MediaSample;
21 class StreamInfo;
22 
25 class MediaStream {
26  public:
27  enum MediaStreamOperation {
28  kPush,
29  kPull,
30  };
33  MediaStream(std::shared_ptr<StreamInfo> info, Demuxer* demuxer);
34  ~MediaStream();
35 
38  void Connect(Muxer* muxer);
39 
41  Status Start(MediaStreamOperation operation);
42 
44  Status PushSample(const std::shared_ptr<MediaSample>& sample);
45 
47  Status PullSample(std::shared_ptr<MediaSample>* sample);
48 
49  Demuxer* demuxer() { return demuxer_; }
50  Muxer* muxer() { return muxer_; }
51  const std::shared_ptr<StreamInfo> info() const;
52 
54  std::string ToString() const;
55 
56  private:
57  MediaStream(const MediaStream&) = delete;
58  MediaStream& operator=(const MediaStream&) = delete;
59 
60  // State transition diagram available @ http://goo.gl/ThJQbl.
61  enum State {
62  kIdle,
63  kConnected,
64  kDisconnected,
65  kPushing,
66  kPulling,
67  };
68 
69  std::shared_ptr<StreamInfo> info_;
70  Demuxer* demuxer_;
71  Muxer* muxer_;
72  State state_;
73  // An internal buffer to store samples temporarily.
74  std::deque<std::shared_ptr<MediaSample>> samples_;
75 };
76 
77 } // namespace media
78 } // namespace shaka
79 
80 #endif // MEDIA_BASE_MEDIA_STREAM_H_
MediaStream(std::shared_ptr< StreamInfo > info, Demuxer *demuxer)
Definition: media_stream.cc:19
Status PushSample(const std::shared_ptr< MediaSample > &sample)
Push sample to Muxer (triggered by Demuxer).
Definition: media_stream.cc:39
Status Start(MediaStreamOperation operation)
Start the stream for pushing or pulling.
Definition: media_stream.cc:62
void Connect(Muxer *muxer)
Definition: media_stream.cc:55
Status PullSample(std::shared_ptr< MediaSample > *sample)
Pull sample from Demuxer (triggered by Muxer).
Definition: media_stream.cc:24
std::string ToString() const