2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
#ifndef PACKAGER_STATUS_H_
|
|
|
|
#define PACKAGER_STATUS_H_
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2015-12-22 19:19:22 +00:00
|
|
|
#include <iostream>
|
2013-10-11 21:44:55 +00:00
|
|
|
#include <string>
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/macros.h>
|
2017-06-29 22:23:53 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
namespace error {
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Error codes for the packager APIs.
|
2013-10-11 21:44:55 +00:00
|
|
|
enum Code {
|
|
|
|
// Not an error; returned on success
|
|
|
|
OK,
|
|
|
|
|
|
|
|
// Unknown error. An example of where this error may be returned is
|
|
|
|
// errors raised by APIs that do not return enough error information
|
|
|
|
// may be converted to this error.
|
|
|
|
UNKNOWN,
|
|
|
|
|
|
|
|
// The operation was cancelled (typically by the caller).
|
|
|
|
CANCELLED,
|
|
|
|
|
|
|
|
// Client specified an invalid argument. INVALID_ARGUMENT indicates
|
|
|
|
// arguments that are problematic regardless of the state of the system
|
|
|
|
// (e.g. a malformed file name).
|
|
|
|
INVALID_ARGUMENT,
|
|
|
|
|
|
|
|
// Operation is not implemented or not supported/enabled.
|
|
|
|
UNIMPLEMENTED,
|
|
|
|
|
|
|
|
// Cannot open file.
|
|
|
|
FILE_FAILURE,
|
|
|
|
|
2013-11-12 20:32:44 +00:00
|
|
|
// End of stream.
|
|
|
|
END_OF_STREAM,
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2013-12-16 17:13:29 +00:00
|
|
|
// Failure to get HTTP response successfully,
|
|
|
|
HTTP_FAILURE,
|
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
// Unable to parse the media file.
|
|
|
|
PARSER_FAILURE,
|
|
|
|
|
2017-02-02 18:28:29 +00:00
|
|
|
// Failed to do the encryption.
|
|
|
|
ENCRYPTION_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
|
|
|
// Error when trying to do chunking.
|
|
|
|
CHUNKING_ERROR,
|
|
|
|
|
2013-11-12 20:32:44 +00:00
|
|
|
// Fail to mux the media file.
|
|
|
|
MUXER_FAILURE,
|
|
|
|
|
|
|
|
// This track fragment is finalized.
|
|
|
|
FRAGMENT_FINALIZED,
|
|
|
|
|
2014-01-14 04:52:05 +00:00
|
|
|
// Server errors. Receives malformed response from server.
|
|
|
|
SERVER_ERROR,
|
|
|
|
|
|
|
|
// Internal errors. Some invariants have been broken.
|
|
|
|
INTERNAL_ERROR,
|
2014-04-07 19:40:52 +00:00
|
|
|
|
|
|
|
// The operation was stopped.
|
|
|
|
STOPPED,
|
|
|
|
|
|
|
|
// The operation timed out.
|
|
|
|
TIME_OUT,
|
2014-08-25 22:51:19 +00:00
|
|
|
|
|
|
|
// Value was not found.
|
|
|
|
NOT_FOUND,
|
2017-01-23 22:51:00 +00:00
|
|
|
|
|
|
|
// The entity that a client attempted to create (e.g., file or directory)
|
|
|
|
// already exists.
|
|
|
|
ALREADY_EXISTS,
|
2017-02-27 17:22:25 +00:00
|
|
|
|
|
|
|
// Error when trying to generate trick play stream.
|
|
|
|
TRICK_PLAY_ERROR,
|
2013-10-11 21:44:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace error
|
|
|
|
|
2017-06-29 22:23:53 +00:00
|
|
|
class SHAKA_EXPORT Status {
|
2013-10-11 21:44:55 +00:00
|
|
|
public:
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Creates a "successful" status.
|
2013-10-11 21:44:55 +00:00
|
|
|
Status() : error_code_(error::OK) {}
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Create a status with the specified code, and error message.
|
|
|
|
/// If "error_code == error::OK", error_message is ignored and a Status
|
|
|
|
/// object identical to Status::OK is constructed.
|
2018-01-23 00:09:14 +00:00
|
|
|
Status(error::Code error_code, const std::string& error_message);
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// @name Some pre-defined Status objects.
|
|
|
|
/// @{
|
2015-12-22 19:19:22 +00:00
|
|
|
static const Status OK; // Identical to 0-arg constructor.
|
|
|
|
static const Status UNKNOWN;
|
2014-01-24 18:46:46 +00:00
|
|
|
/// @}
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// If "ok()", stores "new_status" into *this. If "!ok()", preserves
|
|
|
|
/// the current "error_code()/error_message()",
|
|
|
|
///
|
|
|
|
/// Convenient way of keeping track of the first error encountered.
|
|
|
|
/// Instead of:
|
|
|
|
/// if (overall_status.ok()) overall_status = new_status
|
|
|
|
/// Use:
|
|
|
|
/// overall_status.Update(new_status);
|
2018-01-23 00:09:14 +00:00
|
|
|
void Update(Status new_status);
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2013-11-12 20:32:44 +00:00
|
|
|
bool ok() const { return error_code_ == error::OK; }
|
|
|
|
error::Code error_code() const { return error_code_; }
|
|
|
|
const std::string& error_message() const { return error_message_; }
|
2013-10-11 21:44:55 +00:00
|
|
|
|
|
|
|
bool operator==(const Status& x) const {
|
|
|
|
return error_code_ == x.error_code() && error_message_ == x.error_message();
|
|
|
|
}
|
2013-11-12 20:32:44 +00:00
|
|
|
bool operator!=(const Status& x) const { return !(*this == x); }
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// @return A combination of the error code name and message.
|
2013-10-11 21:44:55 +00:00
|
|
|
std::string ToString() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
error::Code error_code_;
|
|
|
|
std::string error_message_;
|
|
|
|
|
|
|
|
// Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
|
|
|
|
// generated copy constructor and assignment operator.
|
|
|
|
};
|
|
|
|
|
2023-09-09 00:44:17 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os, const Status& x);
|
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
|
|
|
|
2017-06-29 22:23:53 +00:00
|
|
|
#endif // PACKAGER_STATUS_H_
|