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 
12 #include "packager/base/memory/ref_counted.h"
13 #include "packager/base/memory/scoped_ptr.h"
14 #include "packager/media/base/status.h"
15 
16 namespace shaka {
17 namespace media {
18 
19 class Demuxer;
20 class Muxer;
21 class MediaSample;
22 class StreamInfo;
23 
26 class MediaStream {
27  public:
28  enum MediaStreamOperation {
29  kPush,
30  kPull,
31  };
34  MediaStream(scoped_refptr<StreamInfo> info, Demuxer* demuxer);
35  ~MediaStream();
36 
39  void Connect(Muxer* muxer);
40 
42  Status Start(MediaStreamOperation operation);
43 
45  Status PushSample(const scoped_refptr<MediaSample>& sample);
46 
48  Status PullSample(scoped_refptr<MediaSample>* sample);
49 
50  Demuxer* demuxer() { return demuxer_; }
51  Muxer* muxer() { return muxer_; }
52  const scoped_refptr<StreamInfo> info() const;
53 
55  std::string ToString() const;
56 
57  private:
58  // State transition diagram available @ http://goo.gl/ThJQbl.
59  enum State {
60  kIdle,
61  kConnected,
62  kDisconnected,
63  kPushing,
64  kPulling,
65  };
66 
67  scoped_refptr<StreamInfo> info_;
68  Demuxer* demuxer_;
69  Muxer* muxer_;
70  State state_;
71  // An internal buffer to store samples temporarily.
72  std::deque<scoped_refptr<MediaSample> > samples_;
73 
74  DISALLOW_COPY_AND_ASSIGN(MediaStream);
75 };
76 
77 } // namespace media
78 } // namespace shaka
79 
80 #endif // MEDIA_BASE_MEDIA_STREAM_H_
Status PullSample(scoped_refptr< MediaSample > *sample)
Pull sample from Demuxer (triggered by Muxer).
Definition: media_stream.cc:24
Status Start(MediaStreamOperation operation)
Start the stream for pushing or pulling.
Definition: media_stream.cc:62
Status PushSample(const scoped_refptr< MediaSample > &sample)
Push sample to Muxer (triggered by Demuxer).
Definition: media_stream.cc:39
MediaStream(scoped_refptr< StreamInfo > info, Demuxer *demuxer)
Definition: media_stream.cc:19
void Connect(Muxer *muxer)
Definition: media_stream.cc:55
std::string ToString() const