2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
#ifndef MEDIA_BASE_DEMUXER_H_
|
|
|
|
#define MEDIA_BASE_DEMUXER_H_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/memory/ref_counted.h"
|
|
|
|
#include "packager/base/memory/scoped_ptr.h"
|
|
|
|
#include "packager/media/base/container_names.h"
|
|
|
|
#include "packager/media/base/status.h"
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2013-10-11 21:44:55 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class Decryptor;
|
|
|
|
class File;
|
2014-08-25 22:51:19 +00:00
|
|
|
class KeySource;
|
2013-10-11 21:44:55 +00:00
|
|
|
class MediaParser;
|
|
|
|
class MediaSample;
|
|
|
|
class MediaStream;
|
|
|
|
class StreamInfo;
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Demuxer is responsible for extracting elementary stream samples from a
|
|
|
|
/// media file, e.g. an ISO BMFF file.
|
2013-10-11 21:44:55 +00:00
|
|
|
class Demuxer {
|
|
|
|
public:
|
2014-01-24 18:46:46 +00:00
|
|
|
/// @param file_name specifies the input source. It uses prefix matching to
|
|
|
|
/// create a proper File object. The user can extend File to support
|
|
|
|
/// a custom File object with its own prefix.
|
2014-08-25 22:51:19 +00:00
|
|
|
explicit Demuxer(const std::string& file_name);
|
2013-10-11 21:44:55 +00:00
|
|
|
~Demuxer();
|
|
|
|
|
2014-08-25 22:51:19 +00:00
|
|
|
/// Set the KeySource for media decryption.
|
|
|
|
/// @param key_source points to the source of decryption keys. The key
|
|
|
|
/// source must support fetching of keys for the type of media being
|
|
|
|
/// demuxed.
|
|
|
|
void SetKeySource(scoped_ptr<KeySource> key_source);
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Initialize the Demuxer. Calling other public methods of this class
|
|
|
|
/// without this method returning OK, results in an undefined behavior.
|
|
|
|
/// This method primes the demuxer by parsing portions of the media file to
|
|
|
|
/// extract stream information.
|
|
|
|
/// @return OK on success.
|
2013-10-11 21:44:55 +00:00
|
|
|
Status Initialize();
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Drive the remuxing from demuxer side (push). Read the file and push
|
|
|
|
/// the Data to Muxer until Eof.
|
2013-10-11 21:44:55 +00:00
|
|
|
Status Run();
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Read from the source and send it to the parser.
|
2013-10-11 21:44:55 +00:00
|
|
|
Status Parse();
|
|
|
|
|
2015-02-09 18:22:28 +00:00
|
|
|
/// Cancel a demuxing job in progress. Will cause @a Run to exit with an error
|
|
|
|
/// status of type CANCELLED.
|
|
|
|
void Cancel();
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// @return Streams in the media container being demuxed. The caller cannot
|
|
|
|
/// add or remove streams from the returned vector, but the caller is
|
|
|
|
/// allowed to change the internal state of the streams in the vector
|
|
|
|
/// through MediaStream APIs.
|
2013-11-12 20:32:44 +00:00
|
|
|
const std::vector<MediaStream*>& streams() { return streams_; }
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Parser event handlers.
|
|
|
|
void ParserInitEvent(const std::vector<scoped_refptr<StreamInfo> >& streams);
|
2014-09-30 21:52:21 +00:00
|
|
|
bool NewSampleEvent(uint32_t track_id,
|
2013-10-11 21:44:55 +00:00
|
|
|
const scoped_refptr<MediaSample>& sample);
|
|
|
|
|
|
|
|
std::string file_name_;
|
|
|
|
File* media_file_;
|
|
|
|
bool init_event_received_;
|
2014-10-14 02:34:29 +00:00
|
|
|
Status init_parsing_status_;
|
2013-10-11 21:44:55 +00:00
|
|
|
scoped_ptr<MediaParser> parser_;
|
|
|
|
std::vector<MediaStream*> streams_;
|
2014-09-30 21:52:21 +00:00
|
|
|
scoped_ptr<uint8_t[]> buffer_;
|
2014-08-25 22:51:19 +00:00
|
|
|
scoped_ptr<KeySource> key_source_;
|
2015-02-09 18:22:28 +00:00
|
|
|
bool cancelled_;
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Demuxer);
|
|
|
|
};
|
2013-11-21 22:33:07 +00:00
|
|
|
|
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_BASE_DEMUXER_H_
|