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-11-12 20:37:58 +00:00
|
|
|
//
|
|
|
|
// Defines the muxer interface.
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
#ifndef MEDIA_BASE_MUXER_H_
|
|
|
|
#define MEDIA_BASE_MUXER_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/base/time/clock.h"
|
2016-04-08 18:41:17 +00:00
|
|
|
#include "packager/media/base/fourccs.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/muxer_options.h"
|
|
|
|
#include "packager/media/base/status.h"
|
2015-05-05 23:30:14 +00:00
|
|
|
#include "packager/media/event/muxer_listener.h"
|
2015-05-11 21:07:10 +00:00
|
|
|
#include "packager/media/event/progress_listener.h"
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-10-11 21:44:55 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-08-20 23:51:15 +00:00
|
|
|
class KeySource;
|
2013-10-11 21:44:55 +00:00
|
|
|
class MediaSample;
|
|
|
|
class MediaStream;
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Muxer is responsible for taking elementary stream samples and producing
|
2014-08-20 23:51:15 +00:00
|
|
|
/// media containers. An optional KeySource can be provided to Muxer
|
2014-04-16 01:09:32 +00:00
|
|
|
/// to generate encrypted outputs.
|
2013-10-11 21:44:55 +00:00
|
|
|
class Muxer {
|
|
|
|
public:
|
2014-01-14 01:38:34 +00:00
|
|
|
explicit Muxer(const MuxerOptions& options);
|
2013-10-11 21:44:55 +00:00
|
|
|
virtual ~Muxer();
|
|
|
|
|
2014-04-16 01:09:32 +00:00
|
|
|
/// Set encryption key source.
|
2014-08-20 23:51:15 +00:00
|
|
|
/// @param encryption_key_source points to the encryption key source. The
|
|
|
|
/// caller retains ownership, and should not be NULL.
|
2014-04-24 21:32:18 +00:00
|
|
|
/// @param max_sd_pixels specifies the threshold to determine whether a video
|
|
|
|
/// track should be considered as SD or HD. If the track has more
|
|
|
|
/// pixels per frame than max_sd_pixels, it is HD, SD otherwise.
|
2014-04-09 17:34:55 +00:00
|
|
|
/// @param clear_lead_in_seconds specifies clear lead duration in seconds.
|
2014-04-18 18:49:49 +00:00
|
|
|
/// @param crypto_period_duration_in_seconds specifies crypto period duration
|
|
|
|
/// in seconds. A positive value means key rotation is enabled, the
|
|
|
|
/// key source must support key rotation in this case.
|
2016-04-08 18:41:17 +00:00
|
|
|
/// @param protection_scheme specifies the protection scheme: 'cenc', 'cens',
|
|
|
|
/// 'cbc1', 'cbcs'.
|
2014-08-20 23:51:15 +00:00
|
|
|
void SetKeySource(KeySource* encryption_key_source,
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t max_sd_pixels,
|
2014-08-20 23:51:15 +00:00
|
|
|
double clear_lead_in_seconds,
|
2016-03-17 17:03:19 +00:00
|
|
|
double crypto_period_duration_in_seconds,
|
2016-04-08 18:41:17 +00:00
|
|
|
FourCC protection_scheme);
|
2014-01-14 01:38:34 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Add video/audio stream.
|
2014-04-09 17:34:55 +00:00
|
|
|
void AddStream(MediaStream* stream);
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Drive the remuxing from muxer side (pull).
|
2014-04-09 17:34:55 +00:00
|
|
|
Status Run();
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2015-02-09 18:22:28 +00:00
|
|
|
/// Cancel a muxing 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
|
|
|
/// Set a MuxerListener event handler for this object.
|
|
|
|
/// @param muxer_listener should not be NULL.
|
2015-05-07 21:06:16 +00:00
|
|
|
void SetMuxerListener(scoped_ptr<MuxerListener> muxer_listener);
|
2013-12-12 23:49:31 +00:00
|
|
|
|
2015-05-11 21:07:10 +00:00
|
|
|
/// Set a ProgressListener event handler for this object.
|
|
|
|
/// @param progress_listener should not be NULL.
|
|
|
|
void SetProgressListener(scoped_ptr<ProgressListener> progress_listener);
|
|
|
|
|
2013-11-12 20:37:58 +00:00
|
|
|
const std::vector<MediaStream*>& streams() const { return streams_; }
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Inject clock, mainly used for testing.
|
|
|
|
/// The injected clock will be used to generate the creation time-stamp and
|
|
|
|
/// modification time-stamp of the muxer output.
|
|
|
|
/// If no clock is injected, the code uses base::Time::Now() to generate the
|
|
|
|
/// time-stamps.
|
|
|
|
/// @param clock is the Clock to be injected.
|
2014-02-28 02:39:52 +00:00
|
|
|
void set_clock(base::Clock* clock) {
|
|
|
|
clock_ = clock;
|
|
|
|
}
|
|
|
|
|
2013-11-12 20:37:58 +00:00
|
|
|
protected:
|
|
|
|
const MuxerOptions& options() const { return options_; }
|
2014-08-20 23:51:15 +00:00
|
|
|
KeySource* encryption_key_source() {
|
2014-04-16 01:09:32 +00:00
|
|
|
return encryption_key_source_;
|
|
|
|
}
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t max_sd_pixels() const { return max_sd_pixels_; }
|
2014-01-14 01:38:34 +00:00
|
|
|
double clear_lead_in_seconds() const { return clear_lead_in_seconds_; }
|
2014-04-18 18:49:49 +00:00
|
|
|
double crypto_period_duration_in_seconds() const {
|
|
|
|
return crypto_period_duration_in_seconds_;
|
|
|
|
}
|
2015-05-07 21:06:16 +00:00
|
|
|
MuxerListener* muxer_listener() { return muxer_listener_.get(); }
|
2015-05-11 21:07:10 +00:00
|
|
|
ProgressListener* progress_listener() { return progress_listener_.get(); }
|
2014-02-28 02:39:52 +00:00
|
|
|
base::Clock* clock() { return clock_; }
|
2016-04-08 18:41:17 +00:00
|
|
|
FourCC protection_scheme() const { return protection_scheme_; }
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
private:
|
2014-04-09 17:34:55 +00:00
|
|
|
friend class MediaStream; // Needed to access AddSample.
|
|
|
|
|
|
|
|
// Add new media sample.
|
|
|
|
Status AddSample(const MediaStream* stream,
|
|
|
|
scoped_refptr<MediaSample> sample);
|
|
|
|
|
|
|
|
// Initialize the muxer.
|
|
|
|
virtual Status Initialize() = 0;
|
|
|
|
|
|
|
|
// Final clean up.
|
|
|
|
virtual Status Finalize() = 0;
|
|
|
|
|
|
|
|
// AddSample implementation.
|
|
|
|
virtual Status DoAddSample(const MediaStream* stream,
|
|
|
|
scoped_refptr<MediaSample> sample) = 0;
|
|
|
|
|
2013-11-12 20:37:58 +00:00
|
|
|
MuxerOptions options_;
|
2014-04-18 18:49:49 +00:00
|
|
|
bool initialized_;
|
2013-10-11 21:44:55 +00:00
|
|
|
std::vector<MediaStream*> streams_;
|
2014-08-20 23:51:15 +00:00
|
|
|
KeySource* encryption_key_source_;
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t max_sd_pixels_;
|
2014-01-14 01:38:34 +00:00
|
|
|
double clear_lead_in_seconds_;
|
2014-04-18 18:49:49 +00:00
|
|
|
double crypto_period_duration_in_seconds_;
|
2016-04-08 18:41:17 +00:00
|
|
|
FourCC protection_scheme_;
|
2015-02-09 18:22:28 +00:00
|
|
|
bool cancelled_;
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2015-05-07 21:06:16 +00:00
|
|
|
scoped_ptr<MuxerListener> muxer_listener_;
|
2015-05-11 21:07:10 +00:00
|
|
|
scoped_ptr<ProgressListener> progress_listener_;
|
2014-02-28 02:39:52 +00:00
|
|
|
// An external injected clock, can be NULL.
|
|
|
|
base::Clock* clock_;
|
2013-12-12 23:49:31 +00:00
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(Muxer);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_BASE_MUXER_H_
|