summaryrefslogtreecommitdiffstats
path: root/media/cast/receiver
diff options
context:
space:
mode:
authormiu <miu@chromium.org>2015-02-06 21:25:29 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-07 05:26:43 +0000
commit6377eb4a7055d3135e286e71b563ccd100ed4669 (patch)
tree534d35f8ef82297f78afe7c40a0f0df0b9e6ad74 /media/cast/receiver
parent209de48961dcf016f20a8d9afb964ed51ac9ee04 (diff)
downloadchromium_src-6377eb4a7055d3135e286e71b563ccd100ed4669.zip
chromium_src-6377eb4a7055d3135e286e71b563ccd100ed4669.tar.gz
chromium_src-6377eb4a7055d3135e286e71b563ccd100ed4669.tar.bz2
[Cast] Repurpose CastInitializationStatus for variable frame size support.
1. Renamed the CastInitializationStatus enum to OperationalStatus. 2. Renamed CastInitializationCallback to StatusChangeCallback. 3. Documented use of enum and callback. 4. Callbacks may now be run repeatedly to indicate when codec reinit occurs (e.g., for a frame size change), and whether runtime errors occur after initialization. BUG=451277 Review URL: https://codereview.chromium.org/901833004 Cr-Commit-Position: refs/heads/master@{#315187}
Diffstat (limited to 'media/cast/receiver')
-rw-r--r--media/cast/receiver/audio_decoder.cc32
-rw-r--r--media/cast/receiver/audio_decoder.h8
-rw-r--r--media/cast/receiver/audio_decoder_unittest.cc2
-rw-r--r--media/cast/receiver/video_decoder.cc32
-rw-r--r--media/cast/receiver/video_decoder.h8
-rw-r--r--media/cast/receiver/video_decoder_unittest.cc2
6 files changed, 40 insertions, 44 deletions
diff --git a/media/cast/receiver/audio_decoder.cc b/media/cast/receiver/audio_decoder.cc
index 53ac3f0..bc5b596 100644
--- a/media/cast/receiver/audio_decoder.cc
+++ b/media/cast/receiver/audio_decoder.cc
@@ -29,19 +29,19 @@ class AudioDecoder::ImplBase
: cast_environment_(cast_environment),
codec_(codec),
num_channels_(num_channels),
- cast_initialization_status_(STATUS_AUDIO_UNINITIALIZED),
+ operational_status_(STATUS_UNINITIALIZED),
seen_first_frame_(false) {
if (num_channels_ <= 0 || sampling_rate <= 0 || sampling_rate % 100 != 0)
- cast_initialization_status_ = STATUS_INVALID_AUDIO_CONFIGURATION;
+ operational_status_ = STATUS_INVALID_CONFIGURATION;
}
- CastInitializationStatus InitializationResult() const {
- return cast_initialization_status_;
+ OperationalStatus InitializationResult() const {
+ return operational_status_;
}
void DecodeFrame(scoped_ptr<EncodedFrame> encoded_frame,
const DecodeFrameCallback& callback) {
- DCHECK_EQ(cast_initialization_status_, STATUS_AUDIO_INITIALIZED);
+ DCHECK_EQ(operational_status_, STATUS_INITIALIZED);
static_assert(sizeof(encoded_frame->frame_id) == sizeof(last_frame_id_),
"size of frame_id types do not match");
@@ -80,8 +80,8 @@ class AudioDecoder::ImplBase
const Codec codec_;
const int num_channels_;
- // Subclass' ctor is expected to set this to STATUS_AUDIO_INITIALIZED.
- CastInitializationStatus cast_initialization_status_;
+ // Subclass' ctor is expected to set this to STATUS_INITIALIZED.
+ OperationalStatus operational_status_;
private:
bool seen_first_frame_;
@@ -104,15 +104,14 @@ class AudioDecoder::OpusImpl : public AudioDecoder::ImplBase {
max_samples_per_frame_(
kOpusMaxFrameDurationMillis * sampling_rate / 1000),
buffer_(new float[max_samples_per_frame_ * num_channels]) {
- if (ImplBase::cast_initialization_status_ != STATUS_AUDIO_UNINITIALIZED)
+ if (ImplBase::operational_status_ != STATUS_UNINITIALIZED)
return;
if (opus_decoder_init(opus_decoder_, sampling_rate, num_channels) !=
OPUS_OK) {
- ImplBase::cast_initialization_status_ =
- STATUS_INVALID_AUDIO_CONFIGURATION;
+ ImplBase::operational_status_ = STATUS_INVALID_CONFIGURATION;
return;
}
- ImplBase::cast_initialization_status_ = STATUS_AUDIO_INITIALIZED;
+ ImplBase::operational_status_ = STATUS_INITIALIZED;
}
private:
@@ -169,9 +168,9 @@ class AudioDecoder::Pcm16Impl : public AudioDecoder::ImplBase {
CODEC_AUDIO_PCM16,
num_channels,
sampling_rate) {
- if (ImplBase::cast_initialization_status_ != STATUS_AUDIO_UNINITIALIZED)
+ if (ImplBase::operational_status_ != STATUS_UNINITIALIZED)
return;
- ImplBase::cast_initialization_status_ = STATUS_AUDIO_INITIALIZED;
+ ImplBase::operational_status_ = STATUS_INITIALIZED;
}
private:
@@ -219,10 +218,10 @@ AudioDecoder::AudioDecoder(
AudioDecoder::~AudioDecoder() {}
-CastInitializationStatus AudioDecoder::InitializationResult() const {
+OperationalStatus AudioDecoder::InitializationResult() const {
if (impl_.get())
return impl_->InitializationResult();
- return STATUS_UNSUPPORTED_AUDIO_CODEC;
+ return STATUS_UNSUPPORTED_CODEC;
}
void AudioDecoder::DecodeFrame(
@@ -230,8 +229,7 @@ void AudioDecoder::DecodeFrame(
const DecodeFrameCallback& callback) {
DCHECK(encoded_frame.get());
DCHECK(!callback.is_null());
- if (!impl_.get() ||
- impl_->InitializationResult() != STATUS_AUDIO_INITIALIZED) {
+ if (!impl_.get() || impl_->InitializationResult() != STATUS_INITIALIZED) {
callback.Run(make_scoped_ptr<AudioBus>(NULL), false);
return;
}
diff --git a/media/cast/receiver/audio_decoder.h b/media/cast/receiver/audio_decoder.h
index 0b13eae..a68b6fb 100644
--- a/media/cast/receiver/audio_decoder.h
+++ b/media/cast/receiver/audio_decoder.h
@@ -32,10 +32,10 @@ class AudioDecoder {
Codec codec);
virtual ~AudioDecoder();
- // Returns STATUS_AUDIO_INITIALIZED if the decoder was successfully
- // constructed from the given FrameReceiverConfig. If this method returns any
- // other value, calls to DecodeFrame() will not succeed.
- CastInitializationStatus InitializationResult() const;
+ // Returns STATUS_INITIALIZED if the decoder was successfully constructed from
+ // the given FrameReceiverConfig. If this method returns any other value,
+ // calls to DecodeFrame() will not succeed.
+ OperationalStatus InitializationResult() const;
// Decode the payload in |encoded_frame| asynchronously. |callback| will be
// invoked on the CastEnvironment::MAIN thread with the result.
diff --git a/media/cast/receiver/audio_decoder_unittest.cc b/media/cast/receiver/audio_decoder_unittest.cc
index ac13af1..6cd4f4e 100644
--- a/media/cast/receiver/audio_decoder_unittest.cc
+++ b/media/cast/receiver/audio_decoder_unittest.cc
@@ -46,7 +46,7 @@ class AudioDecoderTest : public ::testing::TestWithParam<TestScenario> {
GetParam().num_channels,
GetParam().sampling_rate,
GetParam().codec));
- CHECK_EQ(STATUS_AUDIO_INITIALIZED, audio_decoder_->InitializationResult());
+ CHECK_EQ(STATUS_INITIALIZED, audio_decoder_->InitializationResult());
audio_bus_factory_.reset(
new TestAudioBusFactory(GetParam().num_channels,
diff --git a/media/cast/receiver/video_decoder.cc b/media/cast/receiver/video_decoder.cc
index d7bed12..a30394c 100644
--- a/media/cast/receiver/video_decoder.cc
+++ b/media/cast/receiver/video_decoder.cc
@@ -33,16 +33,16 @@ class VideoDecoder::ImplBase
Codec codec)
: cast_environment_(cast_environment),
codec_(codec),
- cast_initialization_status_(STATUS_VIDEO_UNINITIALIZED),
+ operational_status_(STATUS_UNINITIALIZED),
seen_first_frame_(false) {}
- CastInitializationStatus InitializationResult() const {
- return cast_initialization_status_;
+ OperationalStatus InitializationResult() const {
+ return operational_status_;
}
void DecodeFrame(scoped_ptr<EncodedFrame> encoded_frame,
const DecodeFrameCallback& callback) {
- DCHECK_EQ(cast_initialization_status_, STATUS_VIDEO_INITIALIZED);
+ DCHECK_EQ(operational_status_, STATUS_INITIALIZED);
static_assert(sizeof(encoded_frame->frame_id) == sizeof(last_frame_id_),
"size of frame_id types do not match");
@@ -79,8 +79,8 @@ class VideoDecoder::ImplBase
const scoped_refptr<CastEnvironment> cast_environment_;
const Codec codec_;
- // Subclass' ctor is expected to set this to STATUS_VIDEO_INITIALIZED.
- CastInitializationStatus cast_initialization_status_;
+ // Subclass' ctor is expected to set this to STATUS_INITIALIZED.
+ OperationalStatus operational_status_;
private:
bool seen_first_frame_;
@@ -93,7 +93,7 @@ class VideoDecoder::Vp8Impl : public VideoDecoder::ImplBase {
public:
explicit Vp8Impl(const scoped_refptr<CastEnvironment>& cast_environment)
: ImplBase(cast_environment, CODEC_VIDEO_VP8) {
- if (ImplBase::cast_initialization_status_ != STATUS_VIDEO_UNINITIALIZED)
+ if (ImplBase::operational_status_ != STATUS_UNINITIALIZED)
return;
vpx_codec_dec_cfg_t cfg = {0};
@@ -106,16 +106,15 @@ class VideoDecoder::Vp8Impl : public VideoDecoder::ImplBase {
vpx_codec_vp8_dx(),
&cfg,
VPX_CODEC_USE_POSTPROC) != VPX_CODEC_OK) {
- ImplBase::cast_initialization_status_ =
- STATUS_INVALID_VIDEO_CONFIGURATION;
+ ImplBase::operational_status_ = STATUS_INVALID_CONFIGURATION;
return;
}
- ImplBase::cast_initialization_status_ = STATUS_VIDEO_INITIALIZED;
+ ImplBase::operational_status_ = STATUS_INITIALIZED;
}
private:
~Vp8Impl() override {
- if (ImplBase::cast_initialization_status_ == STATUS_VIDEO_INITIALIZED)
+ if (ImplBase::operational_status_ == STATUS_INITIALIZED)
CHECK_EQ(VPX_CODEC_OK, vpx_codec_destroy(&context_));
}
@@ -175,9 +174,9 @@ class VideoDecoder::FakeImpl : public VideoDecoder::ImplBase {
explicit FakeImpl(const scoped_refptr<CastEnvironment>& cast_environment)
: ImplBase(cast_environment, CODEC_VIDEO_FAKE),
last_decoded_id_(-1) {
- if (ImplBase::cast_initialization_status_ != STATUS_VIDEO_UNINITIALIZED)
+ if (ImplBase::operational_status_ != STATUS_UNINITIALIZED)
return;
- ImplBase::cast_initialization_status_ = STATUS_VIDEO_INITIALIZED;
+ ImplBase::operational_status_ = STATUS_INITIALIZED;
}
private:
@@ -237,10 +236,10 @@ VideoDecoder::VideoDecoder(
VideoDecoder::~VideoDecoder() {}
-CastInitializationStatus VideoDecoder::InitializationResult() const {
+OperationalStatus VideoDecoder::InitializationResult() const {
if (impl_.get())
return impl_->InitializationResult();
- return STATUS_UNSUPPORTED_VIDEO_CODEC;
+ return STATUS_UNSUPPORTED_CODEC;
}
void VideoDecoder::DecodeFrame(
@@ -248,8 +247,7 @@ void VideoDecoder::DecodeFrame(
const DecodeFrameCallback& callback) {
DCHECK(encoded_frame.get());
DCHECK(!callback.is_null());
- if (!impl_.get() ||
- impl_->InitializationResult() != STATUS_VIDEO_INITIALIZED) {
+ if (!impl_.get() || impl_->InitializationResult() != STATUS_INITIALIZED) {
callback.Run(make_scoped_refptr<VideoFrame>(NULL), false);
return;
}
diff --git a/media/cast/receiver/video_decoder.h b/media/cast/receiver/video_decoder.h
index f3d8ca2..2b6c859 100644
--- a/media/cast/receiver/video_decoder.h
+++ b/media/cast/receiver/video_decoder.h
@@ -31,10 +31,10 @@ class VideoDecoder {
Codec codec);
virtual ~VideoDecoder();
- // Returns STATUS_VIDEO_INITIALIZED if the decoder was successfully
- // constructed from the given FrameReceiverConfig. If this method returns any
- // other value, calls to DecodeFrame() will not succeed.
- CastInitializationStatus InitializationResult() const;
+ // Returns STATUS_INITIALIZED if the decoder was successfully constructed from
+ // the given FrameReceiverConfig. If this method returns any other value,
+ // calls to DecodeFrame() will not succeed.
+ OperationalStatus InitializationResult() const;
// Decode the payload in |encoded_frame| asynchronously. |callback| will be
// invoked on the CastEnvironment::MAIN thread with the result.
diff --git a/media/cast/receiver/video_decoder_unittest.cc b/media/cast/receiver/video_decoder_unittest.cc
index 6fcde7a..a51ea1d 100644
--- a/media/cast/receiver/video_decoder_unittest.cc
+++ b/media/cast/receiver/video_decoder_unittest.cc
@@ -52,7 +52,7 @@ class VideoDecoderTest : public ::testing::TestWithParam<Codec> {
protected:
void SetUp() override {
video_decoder_.reset(new VideoDecoder(cast_environment_, GetParam()));
- CHECK_EQ(STATUS_VIDEO_INITIALIZED, video_decoder_->InitializationResult());
+ CHECK_EQ(STATUS_INITIALIZED, video_decoder_->InitializationResult());
next_frame_size_ = gfx::Size(kStartingWidth, kStartingHeight);
next_frame_timestamp_ = base::TimeDelta();