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/media/base/container_names.h"
16 #include "packager/media/base/status.h"
17 
18 namespace shaka {
19 namespace media {
20 
21 class Decryptor;
22 class File;
23 class KeySource;
24 class MediaParser;
25 class MediaSample;
26 class MediaStream;
27 class StreamInfo;
28 
31 class Demuxer {
32  public:
36  explicit Demuxer(const std::string& file_name);
37  ~Demuxer();
38 
43  void SetKeySource(std::unique_ptr<KeySource> key_source);
44 
51 
54  Status Run();
55 
57  Status Parse();
58 
61  void Cancel();
62 
67  const std::vector<std::unique_ptr<MediaStream>>& streams() {
68  return streams_;
69  }
70 
73  MediaContainerName container_name() { return container_name_; }
74 
75  private:
76  Demuxer(const Demuxer&) = delete;
77  Demuxer& operator=(const Demuxer&) = delete;
78 
79  struct QueuedSample {
80  QueuedSample(uint32_t track_id, std::shared_ptr<MediaSample> sample);
81  ~QueuedSample();
82 
83  uint32_t track_id;
84  std::shared_ptr<MediaSample> sample;
85  };
86 
87  // Parser init event.
88  void ParserInitEvent(const std::vector<std::shared_ptr<StreamInfo>>& streams);
89  // Parser new sample event handler. Queues the samples if init event has not
90  // been received, otherwise calls PushSample() to push the sample to
91  // corresponding stream.
92  bool NewSampleEvent(uint32_t track_id,
93  const std::shared_ptr<MediaSample>& sample);
94  // Helper function to push the sample to corresponding stream.
95  bool PushSample(uint32_t track_id,
96  const std::shared_ptr<MediaSample>& sample);
97 
98  std::string file_name_;
99  File* media_file_;
100  bool init_event_received_;
101  Status init_parsing_status_;
102  // Queued samples received in NewSampleEvent() before ParserInitEvent().
103  std::deque<QueuedSample> queued_samples_;
104  std::unique_ptr<MediaParser> parser_;
105  std::vector<std::unique_ptr<MediaStream>> streams_;
106  MediaContainerName container_name_;
107  std::unique_ptr<uint8_t[]> buffer_;
108  std::unique_ptr<KeySource> key_source_;
109  bool cancelled_;
110 };
111 
112 } // namespace media
113 } // namespace shaka
114 
115 #endif // MEDIA_BASE_DEMUXER_H_
MediaContainerName container_name()
Definition: demuxer.h:73
void SetKeySource(std::unique_ptr< KeySource > key_source)
Definition: demuxer.cc:50
const std::vector< std::unique_ptr< MediaStream > > & streams()
Definition: demuxer.h:67
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