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>
|
|
|
|
|
|
|
|
#include "base/memory/ref_counted.h"
|
|
|
|
#include "base/memory/scoped_ptr.h"
|
2013-11-12 20:37:58 +00:00
|
|
|
#include "media/base/muxer_options.h"
|
2013-10-11 21:44:55 +00:00
|
|
|
#include "media/base/status.h"
|
|
|
|
|
2014-02-28 02:39:52 +00:00
|
|
|
namespace base {
|
|
|
|
class Clock;
|
|
|
|
}
|
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
class EncryptorSource;
|
|
|
|
class MediaSample;
|
|
|
|
class MediaStream;
|
|
|
|
|
2013-12-12 23:49:31 +00:00
|
|
|
namespace event {
|
|
|
|
class MuxerListener;
|
|
|
|
}
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Muxer is responsible for taking elementary stream samples and producing
|
|
|
|
/// media containers. An optional EncryptorSource can be provided to Muxer 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-09 17:34:55 +00:00
|
|
|
/// Set encryptor source.
|
|
|
|
/// @param encryptor_source points to the encryptor source to be injected.
|
|
|
|
/// Should not be NULL.
|
|
|
|
/// @param clear_lead_in_seconds specifies clear lead duration in seconds.
|
2014-01-14 01:38:34 +00:00
|
|
|
void SetEncryptorSource(EncryptorSource* encryptor_source,
|
|
|
|
double clear_lead_in_seconds);
|
|
|
|
|
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
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Set a MuxerListener event handler for this object.
|
|
|
|
/// @param muxer_listener should not be NULL.
|
2013-12-12 23:49:31 +00:00
|
|
|
void SetMuxerListener(event::MuxerListener* muxer_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_; }
|
|
|
|
EncryptorSource* encryptor_source() { return encryptor_source_; }
|
2014-01-14 01:38:34 +00:00
|
|
|
double clear_lead_in_seconds() const { return clear_lead_in_seconds_; }
|
2013-12-12 23:49:31 +00:00
|
|
|
event::MuxerListener* muxer_listener() { return muxer_listener_; }
|
2014-02-28 02:39:52 +00:00
|
|
|
base::Clock* clock() { return clock_; }
|
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_;
|
2013-10-11 21:44:55 +00:00
|
|
|
std::vector<MediaStream*> streams_;
|
2014-01-14 01:38:34 +00:00
|
|
|
EncryptorSource* encryptor_source_;
|
2014-04-09 17:34:55 +00:00
|
|
|
bool initialized_;
|
2014-01-14 01:38:34 +00:00
|
|
|
double clear_lead_in_seconds_;
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2013-12-12 23:49:31 +00:00
|
|
|
event::MuxerListener* muxer_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
|
|
|
|
|
|
|
|
#endif // MEDIA_BASE_MUXER_H_
|