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
|
|
|
|
2017-06-29 22:23:53 +00:00
|
|
|
#include "packager/status.h"
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2015-12-22 19:19:22 +00:00
|
|
|
#include "packager/base/logging.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/strings/stringprintf.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
|
|
|
|
2014-03-05 23:15:22 +00:00
|
|
|
namespace error {
|
|
|
|
namespace {
|
2018-12-07 01:35:53 +00:00
|
|
|
const char* ErrorCodeToString(Code error_code) {
|
2014-03-05 23:15:22 +00:00
|
|
|
switch (error_code) {
|
|
|
|
case OK:
|
|
|
|
return "OK";
|
|
|
|
case UNKNOWN:
|
|
|
|
return "UNKNOWN";
|
|
|
|
case CANCELLED:
|
|
|
|
return "CANCELLED";
|
|
|
|
case INVALID_ARGUMENT:
|
|
|
|
return "INVALID_ARGUMENT";
|
|
|
|
case UNIMPLEMENTED:
|
|
|
|
return "UNIMPLEMENTED";
|
|
|
|
case FILE_FAILURE:
|
|
|
|
return "FILE_FAILURE";
|
|
|
|
case END_OF_STREAM:
|
|
|
|
return "END_OF_STREAM";
|
|
|
|
case HTTP_FAILURE:
|
|
|
|
return "HTTP_FAILURE";
|
|
|
|
case PARSER_FAILURE:
|
|
|
|
return "PARSER_FAILURE";
|
Implement ChunkingHandler
This handler is a multi-in multi-out handler. If more than one input is
provided, there should be one and only one video stream; also, all inputs
should come from the same thread and are synchronized.
There can be multiple chunking handler running in different threads or even
different processes, we use the "consistent chunking algorithm" to make sure
the chunks in different streams are aligned without explicit communcating
with each other - which is not efficient and often difficult.
Consistent Chunking Algorithm:
1. Find the consistent chunkable boundary
Let the timestamps for video frames be (t1, t2, t3, ...). Then a
consistent chunkable boundary is simply the first chunkable boundary after
(tk / N) != (tk-1 / N), where '/' denotes integer division, and N is the
intended chunk duration.
2. Chunk only at the consistent chunkable boundary
This algorithm will make sure the chunks from different video streams are
aligned if they have aligned GoPs. However, this algorithm will only work
for video streams. To be able to chunk non video streams at similar
positions as video streams, ChunkingHandler is designed to accept one video
input and multiple non video inputs, the non video inputs are chunked when
the video input is chunked. If the inputs are synchronized - which is true
if the inputs come from the same demuxer, the video and non video chunks
are aligned.
Change-Id: Id3bad51ab14f311efdb8713b6cd36d36cf9e4639
2017-02-07 18:58:47 +00:00
|
|
|
case ENCRYPTION_FAILURE:
|
|
|
|
return "ENCRYPTION_FAILURE";
|
|
|
|
case CHUNKING_ERROR:
|
|
|
|
return "CHUNKING_ERROR";
|
2014-03-05 23:15:22 +00:00
|
|
|
case MUXER_FAILURE:
|
|
|
|
return "MUXER_FAILURE";
|
|
|
|
case FRAGMENT_FINALIZED:
|
|
|
|
return "FRAGMENT_FINALIZED";
|
|
|
|
case SERVER_ERROR:
|
|
|
|
return "SERVER_ERROR";
|
|
|
|
case INTERNAL_ERROR:
|
|
|
|
return "INTERNAL_ERROR";
|
2014-04-07 19:40:52 +00:00
|
|
|
case STOPPED:
|
|
|
|
return "STOPPED";
|
|
|
|
case TIME_OUT:
|
|
|
|
return "TIME_OUT";
|
Implement ChunkingHandler
This handler is a multi-in multi-out handler. If more than one input is
provided, there should be one and only one video stream; also, all inputs
should come from the same thread and are synchronized.
There can be multiple chunking handler running in different threads or even
different processes, we use the "consistent chunking algorithm" to make sure
the chunks in different streams are aligned without explicit communcating
with each other - which is not efficient and often difficult.
Consistent Chunking Algorithm:
1. Find the consistent chunkable boundary
Let the timestamps for video frames be (t1, t2, t3, ...). Then a
consistent chunkable boundary is simply the first chunkable boundary after
(tk / N) != (tk-1 / N), where '/' denotes integer division, and N is the
intended chunk duration.
2. Chunk only at the consistent chunkable boundary
This algorithm will make sure the chunks from different video streams are
aligned if they have aligned GoPs. However, this algorithm will only work
for video streams. To be able to chunk non video streams at similar
positions as video streams, ChunkingHandler is designed to accept one video
input and multiple non video inputs, the non video inputs are chunked when
the video input is chunked. If the inputs are synchronized - which is true
if the inputs come from the same demuxer, the video and non video chunks
are aligned.
Change-Id: Id3bad51ab14f311efdb8713b6cd36d36cf9e4639
2017-02-07 18:58:47 +00:00
|
|
|
case NOT_FOUND:
|
|
|
|
return "NOT_FOUND";
|
|
|
|
case ALREADY_EXISTS:
|
|
|
|
return "ALREADY_EXISTS";
|
2018-12-07 01:35:53 +00:00
|
|
|
case TRICK_PLAY_ERROR:
|
|
|
|
return "TRICK_PLAY_ERROR";
|
2014-03-05 23:15:22 +00:00
|
|
|
}
|
2018-12-07 01:35:53 +00:00
|
|
|
|
|
|
|
NOTIMPLEMENTED() << "Unknown Status Code: " << error_code;
|
|
|
|
return "UNKNOWN_STATUS";
|
2014-03-05 23:15:22 +00:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
} // namespace error
|
|
|
|
|
2015-12-22 19:19:22 +00:00
|
|
|
const Status Status::OK = Status(error::OK, "");
|
|
|
|
const Status Status::UNKNOWN = Status(error::UNKNOWN, "");
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2018-01-23 00:09:14 +00:00
|
|
|
Status::Status(error::Code error_code, const std::string& error_message)
|
|
|
|
: error_code_(error_code) {
|
|
|
|
if (!ok()) {
|
|
|
|
error_message_ = error_message;
|
|
|
|
if (!error_message.empty())
|
|
|
|
VLOG(1) << ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Status::Update(Status new_status) {
|
|
|
|
if (ok())
|
|
|
|
*this = std::move(new_status);
|
|
|
|
}
|
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
std::string Status::ToString() const {
|
|
|
|
if (error_code_ == error::OK)
|
|
|
|
return "OK";
|
|
|
|
|
2018-12-07 01:35:53 +00:00
|
|
|
return base::StringPrintf("%d (%s): %s", error_code_,
|
|
|
|
error::ErrorCodeToString(error_code_),
|
2014-03-05 23:15:22 +00:00
|
|
|
error_message_.c_str());
|
2013-10-11 21:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& os, const Status& x) {
|
|
|
|
os << x.ToString();
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|