media: ffmpeg: Add a separate flush helper for encoder.

The decoder and encoder uses different calls for flushing. Add a new
flush_encoder helper for that, and rename the existing one to
flush_decoder.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p devices

Change-Id: Id237424209dc8d64d43424570003d735ee164d36
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3868598
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
diff --git a/devices/src/virtio/video/decoder/backend/ffmpeg.rs b/devices/src/virtio/video/decoder/backend/ffmpeg.rs
index 2c84495..462ddcc 100644
--- a/devices/src/virtio/video/decoder/backend/ffmpeg.rs
+++ b/devices/src/virtio/video/decoder/backend/ffmpeg.rs
@@ -303,7 +303,7 @@
                     // Start flushing. `try_receive_frame` will return `FlushCompleted` when the
                     // flush is completed. `TryAgain` will not be returned again until the flush is
                     // completed.
-                    match self.context.flush() {
+                    match self.context.flush_decoder() {
                         // Call ourselves again so we can process the flush.
                         Ok(()) => self.try_receive_frame(),
                         Err(err) => {
diff --git a/media/ffmpeg/src/avcodec.rs b/media/ffmpeg/src/avcodec.rs
index 01f72ac..0085e59 100644
--- a/media/ffmpeg/src/avcodec.rs
+++ b/media/ffmpeg/src/avcodec.rs
@@ -520,10 +520,19 @@
     /// frames for them.
     ///
     /// The flush process is complete when `try_receive_frame` returns `FlushCompleted`,
-    pub fn flush(&mut self) -> Result<(), AvError> {
+    pub fn flush_decoder(&mut self) -> Result<(), AvError> {
         // Safe because the context is valid through the life of this object.
         AvError::result(unsafe { ffi::avcodec_send_packet(self.0, std::ptr::null()) })
     }
+
+    /// Ask the context to start flushing, i.e. to process all pending input frames and produce
+    /// packets for them.
+    ///
+    /// The flush process is complete when `try_receive_packet` returns `FlushCompleted`,
+    pub fn flush_encoder(&mut self) -> Result<(), AvError> {
+        // Safe because the context is valid through the life of this object.
+        AvError::result(unsafe { ffi::avcodec_send_frame(self.0, std::ptr::null()) })
+    }
 }
 
 /// Trait for types that can be used as data provider for a `AVBuffer`.