Added ability to cancel a Demuxer or Muxer run.
Change-Id: Ic4c040ef5084c4ec48206403b6abf8ca3d367ad3
This commit is contained in:
parent
e76b20a282
commit
cf0a1878f7
|
@ -33,7 +33,8 @@ Demuxer::Demuxer(const std::string& file_name)
|
|||
: file_name_(file_name),
|
||||
media_file_(NULL),
|
||||
init_event_received_(false),
|
||||
buffer_(new uint8_t[kBufSize]) {
|
||||
buffer_(new uint8_t[kBufSize]),
|
||||
cancelled_(false) {
|
||||
}
|
||||
|
||||
Demuxer::~Demuxer() {
|
||||
|
@ -127,9 +128,12 @@ Status Demuxer::Run() {
|
|||
return status;
|
||||
}
|
||||
|
||||
while ((status = Parse()).ok())
|
||||
while (!cancelled_ && (status = Parse()).ok())
|
||||
continue;
|
||||
|
||||
if (cancelled_ && status.ok())
|
||||
return Status(error::CANCELLED, "Demuxer run cancelled");
|
||||
|
||||
if (status.error_code() == error::END_OF_STREAM) {
|
||||
// Push EOS sample to muxer to indicate end of stream.
|
||||
const scoped_refptr<MediaSample>& sample = MediaSample::CreateEOSBuffer();
|
||||
|
@ -169,5 +173,9 @@ Status Demuxer::Parse() {
|
|||
"Cannot parse media file " + file_name_);
|
||||
}
|
||||
|
||||
void Demuxer::Cancel() {
|
||||
cancelled_ = true;
|
||||
}
|
||||
|
||||
} // namespace media
|
||||
} // namespace edash_packager
|
||||
|
|
|
@ -55,6 +55,10 @@ class Demuxer {
|
|||
/// Read from the source and send it to the parser.
|
||||
Status Parse();
|
||||
|
||||
/// Cancel a demuxing job in progress. Will cause @a Run to exit with an error
|
||||
/// status of type CANCELLED.
|
||||
void Cancel();
|
||||
|
||||
/// @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
|
||||
|
@ -75,6 +79,7 @@ class Demuxer {
|
|||
std::vector<MediaStream*> streams_;
|
||||
scoped_ptr<uint8_t[]> buffer_;
|
||||
scoped_ptr<KeySource> key_source_;
|
||||
bool cancelled_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Demuxer);
|
||||
};
|
||||
|
|
|
@ -19,6 +19,7 @@ Muxer::Muxer(const MuxerOptions& options)
|
|||
max_sd_pixels_(0),
|
||||
clear_lead_in_seconds_(0),
|
||||
crypto_period_duration_in_seconds_(0),
|
||||
cancelled_(false),
|
||||
muxer_listener_(NULL),
|
||||
clock_(NULL) {}
|
||||
|
||||
|
@ -56,6 +57,9 @@ Status Muxer::Run() {
|
|||
|
||||
uint32_t current_stream_id = 0;
|
||||
while (status.ok()) {
|
||||
if (cancelled_)
|
||||
return Status(error::CANCELLED, "muxer run cancelled");
|
||||
|
||||
scoped_refptr<MediaSample> sample;
|
||||
status = streams_[current_stream_id]->PullSample(&sample);
|
||||
if (!status.ok())
|
||||
|
@ -72,6 +76,10 @@ Status Muxer::Run() {
|
|||
return status.error_code() == error::END_OF_STREAM ? Finalize() : status;
|
||||
}
|
||||
|
||||
void Muxer::Cancel() {
|
||||
cancelled_ = true;
|
||||
}
|
||||
|
||||
void Muxer::SetMuxerListener(media::event::MuxerListener* muxer_listener) {
|
||||
muxer_listener_ = muxer_listener;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,10 @@ class Muxer {
|
|||
/// Drive the remuxing from muxer side (pull).
|
||||
Status Run();
|
||||
|
||||
/// Cancel a muxing job in progress. Will cause @a Run to exit with an error
|
||||
/// status of type CANCELLED.
|
||||
void Cancel();
|
||||
|
||||
/// Set a MuxerListener event handler for this object.
|
||||
/// @param muxer_listener should not be NULL.
|
||||
void SetMuxerListener(event::MuxerListener* muxer_listener);
|
||||
|
@ -110,6 +114,7 @@ class Muxer {
|
|||
uint32_t max_sd_pixels_;
|
||||
double clear_lead_in_seconds_;
|
||||
double crypto_period_duration_in_seconds_;
|
||||
bool cancelled_;
|
||||
|
||||
event::MuxerListener* muxer_listener_;
|
||||
// An external injected clock, can be NULL.
|
||||
|
|
Loading…
Reference in New Issue