void UpdatePreviewRotation(media::VideoRotation);
media::VideoRotation GetVideoRotation();
+ bool PrepareVideoDecoder();
+
+ bool suspended_ = false;
+
Camera* const camera_;
std::unique_ptr<Client> client_;
VideoCaptureParams params_;
TIZEN_MEDIA_LOG(INFO) << "Camera started";
- if (IsEncodedCameraFormat(camera_format_)) {
- MediaVideoCodec codec = CameraToMediaVideoCodec(camera_format_);
- // TODO(vd.wasm) For now, we'll use predefined settings (bit depth and
- // chroma sampling). It should be replaced later with proper
- // received frame parsing.
- auto maybe_configuration = GetVideoConfiguration(codec);
- if (!maybe_configuration) {
- client_->OnError(VideoCaptureError::kV4L2VidiocStreamonFailed, FROM_HERE,
- "Wrong video codec, cannot initialize decoder");
- return;
- }
-
- TIZEN_MEDIA_LOG(INFO) << "Start video decoder initialization for camera";
- decoder_ = std::make_unique<TTvdVideoDecoderBase>(
- base::BindRepeating(&CreateDecoderFacadeVideo));
- decoder_->Initialize(
- codec, kNoVideoCodecLevel, params.SuggestConstraints().max_frame_size,
- maybe_configuration->chroma_sampling, maybe_configuration->bit_depth,
- true,
- base::BindOnce(&VideoCaptureDeviceTizenTv::Impl::OnDecoderInitialized,
- weak_factory_.GetWeakPtr()),
- base::BindRepeating(&VideoCaptureDeviceTizenTv::Impl::OnDecodedFrame,
- weak_factory_.GetWeakPtr()));
+ if (IsEncodedCameraFormat(camera_format_) && !PrepareVideoDecoder()) {
+ client_->OnError(VideoCaptureError::kV4L2VidiocStreamonFailed, FROM_HERE,
+ "Wrong video codec, cannot initialize decoder");
+ return;
}
// For now mark it's started early. There's some problems with
return clockwise_rotation;
}
+bool VideoCaptureDeviceTizenTv::Impl::PrepareVideoDecoder() {
+ MediaVideoCodec codec = CameraToMediaVideoCodec(camera_format_);
+ // TODO(vd.wasm) For now, we'll use predefined settings (bit depth and
+ // chroma sampling). It should be replaced later with proper
+ // received frame parsing.
+ auto maybe_configuration = GetVideoConfiguration(codec);
+ if (!maybe_configuration) {
+ return false;
+ }
+
+ TIZEN_MEDIA_LOG(INFO) << "Start video decoder initialization for camera";
+ decoder_ = std::make_unique<TTvdVideoDecoderBase>(
+ base::BindRepeating(&CreateDecoderFacadeVideo));
+ decoder_->Initialize(
+ codec, kNoVideoCodecLevel, params_.SuggestConstraints().max_frame_size,
+ maybe_configuration->chroma_sampling, maybe_configuration->bit_depth,
+ true,
+ base::BindOnce(&VideoCaptureDeviceTizenTv::Impl::OnDecoderInitialized,
+ weak_factory_.GetWeakPtr()),
+ base::BindRepeating(&VideoCaptureDeviceTizenTv::Impl::OnDecodedFrame,
+ weak_factory_.GetWeakPtr()));
+ return true;
+}
+
void VideoCaptureDeviceTizenTv::Impl::ProcessEncodedCameraCapture(
scoped_refptr<DecoderBuffer> buffer,
media::VideoRotation rotation) {
UpdatePreviewRotation(rotation);
+
+ if (suspended_) {
+ return;
+ }
+
+ if (!decoder_) {
+ TIZEN_MEDIA_LOG(ERROR) << "Cannot process encoded frame without decoder";
+ return;
+ }
decoder_->Decode(std::move(buffer), base::DoNothing());
decoder_->GetNextVideoFrame();
}
}
void VideoCaptureDeviceTizenTv::Impl::MaybeSuspend() {
+ suspended_ = true;
CAMERA_CHECK_AND_RETURN(StopCameraPreview());
+ decoder_.reset();
}
void VideoCaptureDeviceTizenTv::Impl::Resume() {
+ suspended_ = false;
CAMERA_CHECK_AND_RETURN(StartCameraPreview());
+ if (IsEncodedCameraFormat(camera_format_) && !PrepareVideoDecoder()) {
+ TIZEN_MEDIA_LOG(ERROR) << "Cannot resume decoder";
+ }
}
void VideoCaptureDeviceTizenTv::Impl::OnDecodedFrame(RawFrame frame) {