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 <memory>
12 #include <vector>
13 
14 #include "packager/base/compiler_specific.h"
15 #include "packager/base/memory/ref_counted.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(std::unique_ptr<KeySource> key_source);
45 
52 
55  Status Run();
56 
58  Status Parse();
59 
62  void Cancel();
63 
68  const std::vector<std::unique_ptr<MediaStream>>& streams() {
69  return streams_;
70  }
71 
74  MediaContainerName container_name() { return container_name_; }
75 
76  private:
77  struct QueuedSample {
78  QueuedSample(uint32_t track_id, scoped_refptr<MediaSample> sample);
79  ~QueuedSample();
80 
81  uint32_t track_id;
82  scoped_refptr<MediaSample> sample;
83  };
84 
85  // Parser init event.
86  void ParserInitEvent(const std::vector<scoped_refptr<StreamInfo> >& streams);
87  // Parser new sample event handler. Queues the samples if init event has not
88  // been received, otherwise calls PushSample() to push the sample to
89  // corresponding stream.
90  bool NewSampleEvent(uint32_t track_id,
91  const scoped_refptr<MediaSample>& sample);
92  // Helper function to push the sample to corresponding stream.
93  bool PushSample(uint32_t track_id, const scoped_refptr<MediaSample>& sample);
94 
95  std::string file_name_;
96  File* media_file_;
97  bool init_event_received_;
98  Status init_parsing_status_;
99  // Queued samples received in NewSampleEvent() before ParserInitEvent().
100  std::deque<QueuedSample> queued_samples_;
101  std::unique_ptr<MediaParser> parser_;
102  std::vector<std::unique_ptr<MediaStream>> streams_;
103  MediaContainerName container_name_;
104  std::unique_ptr<uint8_t[]> buffer_;
105  std::unique_ptr<KeySource> key_source_;
106  bool cancelled_;
107 
108  DISALLOW_COPY_AND_ASSIGN(Demuxer);
109 };
110 
111 } // namespace media
112 } // namespace shaka
113 
114 #endif // MEDIA_BASE_DEMUXER_H_
MediaContainerName container_name()
Definition: demuxer.h:74
void SetKeySource(std::unique_ptr< KeySource > key_source)
Definition: demuxer.cc:50
const std::vector< std::unique_ptr< MediaStream > > & streams()
Definition: demuxer.h:68
Status Parse()
Read from the source and send it to the parser.
Definition: demuxer.cc:197
Status Initialize()
Definition: demuxer.cc:54
Demuxer(const std::string &file_name)
Definition: demuxer.cc:36