DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
demuxer.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_DEMUXER_H_
8 #define MEDIA_BASE_DEMUXER_H_
9 
10 #include <deque>
11 #include <vector>
12 
13 #include "packager/base/compiler_specific.h"
14 #include "packager/base/memory/ref_counted.h"
15 #include "packager/base/memory/scoped_ptr.h"
16 #include "packager/media/base/container_names.h"
17 #include "packager/media/base/status.h"
18 
19 namespace shaka {
20 namespace media {
21 
22 class Decryptor;
23 class File;
24 class KeySource;
25 class MediaParser;
26 class MediaSample;
27 class MediaStream;
28 class StreamInfo;
29 
32 class Demuxer {
33  public:
37  explicit Demuxer(const std::string& file_name);
38  ~Demuxer();
39 
44  void SetKeySource(scoped_ptr<KeySource> key_source);
45 
52 
55  Status Run();
56 
58  Status Parse();
59 
62  void Cancel();
63 
68  const std::vector<MediaStream*>& streams() { return streams_; }
69 
72  MediaContainerName container_name() { return container_name_; }
73 
74  private:
75  struct QueuedSample {
76  QueuedSample(uint32_t track_id, scoped_refptr<MediaSample> sample);
77  ~QueuedSample();
78 
79  uint32_t track_id;
80  scoped_refptr<MediaSample> sample;
81  };
82 
83  // Parser init event.
84  void ParserInitEvent(const std::vector<scoped_refptr<StreamInfo> >& streams);
85  // Parser new sample event handler. Queues the samples if init event has not
86  // been received, otherwise calls PushSample() to push the sample to
87  // corresponding stream.
88  bool NewSampleEvent(uint32_t track_id,
89  const scoped_refptr<MediaSample>& sample);
90  // Helper function to push the sample to corresponding stream.
91  bool PushSample(uint32_t track_id, const scoped_refptr<MediaSample>& sample);
92 
93  std::string file_name_;
94  File* media_file_;
95  bool init_event_received_;
96  Status init_parsing_status_;
97  // Queued samples received in NewSampleEvent() before ParserInitEvent().
98  std::deque<QueuedSample> queued_samples_;
99  scoped_ptr<MediaParser> parser_;
100  std::vector<MediaStream*> streams_;
101  MediaContainerName container_name_;
102  scoped_ptr<uint8_t[]> buffer_;
103  scoped_ptr<KeySource> key_source_;
104  bool cancelled_;
105 
106  DISALLOW_COPY_AND_ASSIGN(Demuxer);
107 };
108 
109 } // namespace media
110 } // namespace shaka
111 
112 #endif // MEDIA_BASE_DEMUXER_H_
void SetKeySource(scoped_ptr< KeySource > key_source)
Definition: demuxer.cc:52
MediaContainerName container_name()
Definition: demuxer.h:72
const std::vector< MediaStream * > & streams()
Definition: demuxer.h:68
Status Parse()
Read from the source and send it to the parser.
Definition: demuxer.cc:207
Status Initialize()
Definition: demuxer.cc:56
Demuxer(const std::string &file_name)
Definition: demuxer.cc:37