hc
2023-02-13 e440ec23c5a540cdd3f7464e8779219be6fd3d95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
From ede4260fcee7a7b022604ef303285c128c078609 Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Mon, 21 Mar 2022 18:30:22 +0800
Subject: [PATCH 15/15] media/gpu/v4l2: Non-blocking initialize
 
See:
https://bugs.chromium.org/p/chromium/issues/detail?id=1308345
 
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
 .../gpu/v4l2/v4l2_video_encode_accelerator.cc | 35 +++++++++----------
 .../gpu/v4l2/v4l2_video_encode_accelerator.h  |  4 +--
 2 files changed, 17 insertions(+), 22 deletions(-)
 
diff --git a/media/gpu/v4l2/v4l2_video_encode_accelerator.cc b/media/gpu/v4l2/v4l2_video_encode_accelerator.cc
index 0edf56412..488e05828 100644
--- a/media/gpu/v4l2/v4l2_video_encode_accelerator.cc
+++ b/media/gpu/v4l2/v4l2_video_encode_accelerator.cc
@@ -272,25 +272,15 @@ bool V4L2VideoEncodeAccelerator::Initialize(
     return false;
   }
 
-  bool result = false;
-  base::WaitableEvent done;
   encoder_task_runner_->PostTask(
       FROM_HERE, base::BindOnce(&V4L2VideoEncodeAccelerator::InitializeTask,
-                                weak_this_, config, &result, &done));
-  done.Wait();
-  return result;
+                                weak_this_, config));
+  return true;
 }
 
-void V4L2VideoEncodeAccelerator::InitializeTask(const Config& config,
-                                                bool* result,
-                                                base::WaitableEvent* done) {
+void V4L2VideoEncodeAccelerator::InitializeTask(const Config& config) {
   DCHECK_CALLED_ON_VALID_SEQUENCE(encoder_sequence_checker_);
 
-  // Signal the event when leaving the method.
-  base::ScopedClosureRunner signal_event(
-      base::BindOnce(&base::WaitableEvent::Signal, base::Unretained(done)));
-  *result = false;
-
   native_input_mode_ =
       config.storage_type.value_or(Config::StorageType::kShmem) ==
       Config::StorageType::kGpuMemoryBuffer;
@@ -305,6 +295,7 @@ void V4L2VideoEncodeAccelerator::InitializeTask(const Config& config,
 
   if (!SetFormats(config.input_format, config.output_profile)) {
     VLOGF(1) << "Failed setting up formats";
+    NOTIFY_ERROR(kPlatformFailureError);
     return;
   }
 
@@ -318,6 +309,7 @@ void V4L2VideoEncodeAccelerator::InitializeTask(const Config& config,
             VideoFrame::NumPlanes(config.input_format)));
     if (!input_layout) {
       VLOGF(1) << "Invalid image processor input layout";
+      NOTIFY_ERROR(kPlatformFailureError);
       return;
     }
 
@@ -327,6 +319,7 @@ void V4L2VideoEncodeAccelerator::InitializeTask(const Config& config,
                               encoder_input_visible_rect_,
                               encoder_input_visible_rect_)) {
       VLOGF(1) << "Failed to create image processor";
+      NOTIFY_ERROR(kPlatformFailureError);
       return;
     }
 
@@ -338,16 +331,23 @@ void V4L2VideoEncodeAccelerator::InitializeTask(const Config& config,
       VLOGF(1) << "Failed to reconfigure v4l2 encoder driver with the "
                << "ImageProcessor output buffer: "
                << ip_output_buffer_size.ToString();
+      NOTIFY_ERROR(kPlatformFailureError);
       return;
     }
   }
 
-  if (!InitInputMemoryType(config))
+  if (!InitInputMemoryType(config)) {
+    NOTIFY_ERROR(kPlatformFailureError);
     return;
-  if (!InitControls(config))
+  }
+  if (!InitControls(config)) {
+    NOTIFY_ERROR(kPlatformFailureError);
     return;
-  if (!CreateOutputBuffers())
+  }
+  if (!CreateOutputBuffers()) {
+    NOTIFY_ERROR(kPlatformFailureError);
     return;
+  }
 
   encoder_state_ = kInitialized;
   RequestEncodingParametersChangeTask(
@@ -380,9 +380,6 @@ void V4L2VideoEncodeAccelerator::InitializeTask(const Config& config,
   child_task_runner_->PostTask(
       FROM_HERE,
       base::BindOnce(&Client::NotifyEncoderInfoChange, client_, encoder_info));
-
-  // Finish initialization.
-  *result = true;
 }
 
 bool V4L2VideoEncodeAccelerator::CreateImageProcessor(
diff --git a/media/gpu/v4l2/v4l2_video_encode_accelerator.h b/media/gpu/v4l2/v4l2_video_encode_accelerator.h
index d414a327d..ce6cad5ab 100644
--- a/media/gpu/v4l2/v4l2_video_encode_accelerator.h
+++ b/media/gpu/v4l2/v4l2_video_encode_accelerator.h
@@ -200,9 +200,7 @@ class MEDIA_GPU_EXPORT V4L2VideoEncodeAccelerator
                                            uint32_t framerate);
 
   // Do several initializations (e.g. set up format) on |encoder_task_runner_|.
-  void InitializeTask(const Config& config,
-                      bool* result,
-                      base::WaitableEvent* done);
+  void InitializeTask(const Config& config);
 
   // Set up formats and initialize the device for them.
   bool SetFormats(VideoPixelFormat input_format,
-- 
2.20.1