Commit ba021e31 authored by Alexandre Courbot's avatar Alexandre Courbot Committed by Commit Bot

media/gpu/v4l2: use V4L2DevicePoller in V4L2SliceVideoDecoder

Make use of the new polling capabilities of V4L2Device brought by
V4L2DevicePoller to simplify the code.

Bug: 1003223
Test: vdatests passing on Kevin.

Change-Id: Ie44d7d57f5661840f94004f36ac42dae3ebe992f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1799653
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: default avatarChih-Yu Huang <akahuang@chromium.org>
Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700124}
parent 410b74e2
......@@ -168,7 +168,6 @@ V4L2SliceVideoDecoder::V4L2SliceVideoDecoder(
get_pool_cb_(std::move(get_pool_cb)),
client_task_runner_(std::move(client_task_runner)),
decoder_task_runner_(std::move(decoder_task_runner)),
device_poll_thread_("V4L2SliceVideoDecoderDevicePollThread"),
bitstream_id_to_timestamp_(kTimestampCacheSize),
weak_this_factory_(this) {
DETACH_FROM_SEQUENCE(client_sequence_checker_);
......@@ -546,11 +545,11 @@ void V4L2SliceVideoDecoder::ResetTask(base::OnceClosure closure) {
// Streamoff V4L2 queues to drop input and output buffers.
// If the queues are streaming before reset, then we need to start streaming
// them after stopping.
bool poll_thread_running = device_poll_thread_.IsRunning();
bool is_streaming = input_queue_->IsStreaming();
if (!StopStreamV4L2Queue())
return;
if (poll_thread_running) {
if (is_streaming) {
if (!StartStreamV4L2Queue())
return;
}
......@@ -897,8 +896,6 @@ void V4L2SliceVideoDecoder::DecodeSurface(
}
surfaces_at_device_.push(std::move(dec_surface));
SchedulePollTaskIfNeeded();
}
void V4L2SliceVideoDecoder::SurfaceReady(
......@@ -930,21 +927,21 @@ bool V4L2SliceVideoDecoder::StartStreamV4L2Queue() {
DCHECK_CALLED_ON_VALID_SEQUENCE(decoder_sequence_checker_);
DVLOGF(3);
if (!device_poll_thread_.IsRunning()) {
if (!device_poll_thread_.Start()) {
VLOGF(1) << "Failed to start device poll thread.";
SetState(State::kError);
return false;
}
}
if (!input_queue_->Streamon() || !output_queue_->Streamon()) {
VLOGF(1) << "Failed to streamon V4L2 queue.";
SetState(State::kError);
return false;
}
SchedulePollTaskIfNeeded();
if (!device_->StartPolling(
base::BindRepeating(&V4L2SliceVideoDecoder::ServiceDeviceTask,
weak_this_),
base::BindRepeating(&V4L2SliceVideoDecoder::SetState, weak_this_,
State::kError))) {
SetState(State::kError);
return false;
}
return true;
}
......@@ -952,19 +949,7 @@ bool V4L2SliceVideoDecoder::StopStreamV4L2Queue() {
DCHECK_CALLED_ON_VALID_SEQUENCE(decoder_sequence_checker_);
DVLOGF(3);
if (!device_poll_thread_.IsRunning())
return true;
if (!device_->SetDevicePollInterrupt()) {
VLOGF(1) << "Failed to interrupt device poll.";
SetState(State::kError);
return false;
}
DVLOGF(3) << "Stop device poll thead";
device_poll_thread_.Stop();
if (!device_->ClearDevicePollInterrupt()) {
VLOGF(1) << "Failed to clear interrupting device poll.";
if (!device_->StopPolling()) {
SetState(State::kError);
return false;
}
......@@ -981,46 +966,7 @@ bool V4L2SliceVideoDecoder::StopStreamV4L2Queue() {
return true;
}
// Poke when we want to dequeue buffer from V4L2 device
void V4L2SliceVideoDecoder::SchedulePollTaskIfNeeded() {
DVLOGF(3);
DCHECK_CALLED_ON_VALID_SEQUENCE(decoder_sequence_checker_);
DCHECK(input_queue_->IsStreaming() && output_queue_->IsStreaming());
if (!device_poll_thread_.IsRunning()) {
DVLOGF(4) << "Device poll thread stopped, will not schedule poll";
return;
}
if (input_queue_->QueuedBuffersCount() == 0 &&
output_queue_->QueuedBuffersCount() == 0) {
DVLOGF(4) << "No buffers queued, will not schedule poll";
return;
}
device_poll_thread_.task_runner()->PostTask(
FROM_HERE, base::BindOnce(&V4L2SliceVideoDecoder::DevicePollTask,
base::Unretained(this)));
}
void V4L2SliceVideoDecoder::DevicePollTask() {
DCHECK(device_poll_thread_.task_runner()->RunsTasksInCurrentSequence());
DVLOGF(3);
bool event_pending;
if (!device_->Poll(true, &event_pending)) {
decoder_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&V4L2SliceVideoDecoder::SetState, weak_this_,
State::kError));
return;
}
decoder_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&V4L2SliceVideoDecoder::ServiceDeviceTask, weak_this_));
}
void V4L2SliceVideoDecoder::ServiceDeviceTask() {
void V4L2SliceVideoDecoder::ServiceDeviceTask(bool /* event */) {
DCHECK_CALLED_ON_VALID_SEQUENCE(decoder_sequence_checker_);
DVLOGF(3) << "Number of queued input buffers: "
<< input_queue_->QueuedBuffersCount()
......@@ -1076,8 +1022,6 @@ void V4L2SliceVideoDecoder::ServiceDeviceTask() {
break;
}
SchedulePollTaskIfNeeded();
if (resume_decode && pause_reason_ == PauseReason::kWaitSubFrameDecoded) {
decoder_task_runner_->PostTask(
FROM_HERE,
......
......@@ -202,13 +202,8 @@ class MEDIA_GPU_EXPORT V4L2SliceVideoDecoder : public VideoDecoder,
// Stop streaming V4L2 input and output queues. Stop |device_poll_thread_|
// before stopping streaming.
bool StopStreamV4L2Queue();
// Schedule poll if we have any buffers queued and the poll thread is not
// stopped (on surface set change).
void SchedulePollTaskIfNeeded();
// Ran on device_poll_thread_ to wait for device events.
void DevicePollTask();
// Try to dequeue input and output buffers from device.
void ServiceDeviceTask();
void ServiceDeviceTask(bool event);
// Get the next bitsream ID.
int32_t GetNextBitstreamId();
......@@ -236,9 +231,6 @@ class MEDIA_GPU_EXPORT V4L2SliceVideoDecoder : public VideoDecoder,
// members are manipulated on this thread.
const scoped_refptr<base::SequencedTaskRunner> decoder_task_runner_;
// Thread used to poll the device for events.
base::Thread device_poll_thread_;
// State of the instance.
State state_ = State::kUninitialized;
// Indicates why decoding is currently paused.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment