This source file includes following definitions.
- ConvertSecondsToTimestamp
- ConvertToWebTimeRanges
- PipelineErrorToNetworkState
#include "content/renderer/media/webmediaplayer_util.h"
#include <math.h>
#include "media/base/media_keys.h"
#include "third_party/WebKit/public/platform/WebMediaPlayerClient.h"
namespace content {
#define COMPILE_ASSERT_MATCHING_ENUM(name) \
COMPILE_ASSERT( \
static_cast<int>(blink::WebMediaPlayerClient::MediaKeyErrorCode ## name) == \
static_cast<int>(media::MediaKeys::k ## name ## Error), \
mismatching_enums)
COMPILE_ASSERT_MATCHING_ENUM(Unknown);
COMPILE_ASSERT_MATCHING_ENUM(Client);
#undef COMPILE_ASSERT_MATCHING_ENUM
base::TimeDelta ConvertSecondsToTimestamp(double seconds) {
double microseconds = seconds * base::Time::kMicrosecondsPerSecond;
return base::TimeDelta::FromMicroseconds(
microseconds > 0 ? microseconds + 0.5 : ceil(microseconds - 0.5));
}
blink::WebTimeRanges ConvertToWebTimeRanges(
const media::Ranges<base::TimeDelta>& ranges) {
blink::WebTimeRanges result(ranges.size());
for (size_t i = 0; i < ranges.size(); ++i) {
result[i].start = ranges.start(i).InSecondsF();
result[i].end = ranges.end(i).InSecondsF();
}
return result;
}
blink::WebMediaPlayer::NetworkState PipelineErrorToNetworkState(
media::PipelineStatus error) {
DCHECK_NE(error, media::PIPELINE_OK);
switch (error) {
case media::PIPELINE_ERROR_NETWORK:
case media::PIPELINE_ERROR_READ:
return blink::WebMediaPlayer::NetworkStateNetworkError;
case media::PIPELINE_ERROR_INITIALIZATION_FAILED:
case media::PIPELINE_ERROR_COULD_NOT_RENDER:
case media::PIPELINE_ERROR_URL_NOT_FOUND:
case media::DEMUXER_ERROR_COULD_NOT_OPEN:
case media::DEMUXER_ERROR_COULD_NOT_PARSE:
case media::DEMUXER_ERROR_NO_SUPPORTED_STREAMS:
case media::DECODER_ERROR_NOT_SUPPORTED:
return blink::WebMediaPlayer::NetworkStateFormatError;
case media::PIPELINE_ERROR_DECODE:
case media::PIPELINE_ERROR_ABORT:
case media::PIPELINE_ERROR_OPERATION_PENDING:
case media::PIPELINE_ERROR_INVALID_STATE:
return blink::WebMediaPlayer::NetworkStateDecodeError;
case media::PIPELINE_ERROR_DECRYPT:
return blink::WebMediaPlayer::NetworkStateDecodeError;
case media::PIPELINE_OK:
NOTREACHED() << "Unexpected status! " << error;
}
return blink::WebMediaPlayer::NetworkStateFormatError;
}
}