Delete pre_decode_callback.

Only user was the replay.cc tool, when dumping frames to a file. It is
changed to instead inject a special decoder.

Bug: None
Change-Id: I521fbba1a0ef440cff7d786f6f4c6397e33f764f
Reviewed-on: https://webrtc-review.googlesource.com/83121
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23675}
diff --git a/call/video_receive_stream.cc b/call/video_receive_stream.cc
index b42c9f9..7662aff 100644
--- a/call/video_receive_stream.cc
+++ b/call/video_receive_stream.cc
@@ -88,8 +88,6 @@
   ss << ", render_delay_ms: " << render_delay_ms;
   if (!sync_group.empty())
     ss << ", sync_group: " << sync_group;
-  ss << ", pre_decode_callback: "
-     << (pre_decode_callback ? "(EncodedFrameObserver)" : "nullptr");
   ss << ", target_delay_ms: " << target_delay_ms;
   ss << '}';
 
diff --git a/call/video_receive_stream.h b/call/video_receive_stream.h
index a6ae8ef..5009ddb 100644
--- a/call/video_receive_stream.h
+++ b/call/video_receive_stream.h
@@ -213,11 +213,6 @@
     // to one of the audio streams.
     std::string sync_group;
 
-    // Called for each incoming video frame, i.e. in encoded state. E.g. used
-    // when
-    // saving the stream to a file. 'nullptr' disables the callback.
-    EncodedFrameObserver* pre_decode_callback = nullptr;
-
     // Target delay in milliseconds. A positive value indicates this stream is
     // used for streaming instead of a real-time call.
     int target_delay_ms = 0;
diff --git a/test/fake_decoder.h b/test/fake_decoder.h
index 62bfbb8..a90c861 100644
--- a/test/fake_decoder.h
+++ b/test/fake_decoder.h
@@ -57,17 +57,6 @@
                  int64_t render_time_ms) override;
 };
 
-class FakeNullDecoder : public FakeDecoder {
- public:
-  virtual ~FakeNullDecoder() {}
-
-  int32_t Decode(const EncodedImage& input,
-                 bool missing_frames,
-                 const CodecSpecificInfo* codec_specific_info,
-                 int64_t render_time_ms) override {
-    return 0;
-  }
-};
 }  // namespace test
 }  // namespace webrtc
 
diff --git a/video/end_to_end_tests/call_operation_tests.cc b/video/end_to_end_tests/call_operation_tests.cc
index 2c45665..dad4c42 100644
--- a/video/end_to_end_tests/call_operation_tests.cc
+++ b/video/end_to_end_tests/call_operation_tests.cc
@@ -225,15 +225,6 @@
 
     bool Wait() { return called_.Wait(kDefaultTimeoutMs); }
 
-    void ExpectEqualFrames(const EncodedFrameTestObserver& observer) {
-      ASSERT_EQ(length_, observer.length_)
-          << "Observed frames are of different lengths.";
-      EXPECT_EQ(frame_type_, observer.frame_type_)
-          << "Observed frames have different frame types.";
-      EXPECT_EQ(0, memcmp(buffer_.get(), observer.buffer_.get(), length_))
-          << "Observed encoded frames have different content.";
-    }
-
    private:
     std::unique_ptr<uint8_t[]> buffer_;
     size_t length_;
@@ -242,7 +233,6 @@
   };
 
   EncodedFrameTestObserver post_encode_observer;
-  EncodedFrameTestObserver pre_decode_observer;
   test::FrameForwarder forwarder;
   std::unique_ptr<test::FrameGenerator> frame_generator;
 
@@ -262,7 +252,6 @@
     CreateSendConfig(1, 0, 0, sender_transport.get());
     CreateMatchingReceiveConfigs(receiver_transport.get());
     video_send_config_.post_encode_callback = &post_encode_observer;
-    video_receive_configs_[0].pre_decode_callback = &pre_decode_observer;
 
     CreateVideoStreams();
     Start();
@@ -277,11 +266,6 @@
   EXPECT_TRUE(post_encode_observer.Wait())
       << "Timed out while waiting for send-side encoded-frame callback.";
 
-  EXPECT_TRUE(pre_decode_observer.Wait())
-      << "Timed out while waiting for pre-decode encoded-frame callback.";
-
-  post_encode_observer.ExpectEqualFrames(pre_decode_observer);
-
   task_queue_.SendTask([this, &sender_transport, &receiver_transport]() {
     Stop();
     DestroyStreams();
diff --git a/video/replay.cc b/video/replay.cc
index 8362f59..4667aa2 100644
--- a/video/replay.cc
+++ b/video/replay.cc
@@ -201,7 +201,7 @@
   size_t count_;
 };
 
-class DecoderBitstreamFileWriter : public EncodedFrameObserver {
+class DecoderBitstreamFileWriter : public test::FakeDecoder {
  public:
   explicit DecoderBitstreamFileWriter(const char* filename)
       : file_(fopen(filename, "wb")) {
@@ -209,8 +209,16 @@
   }
   ~DecoderBitstreamFileWriter() { fclose(file_); }
 
-  virtual void EncodedFrameCallback(const EncodedFrame& encoded_frame) {
-    fwrite(encoded_frame.data_, 1, encoded_frame.length_, file_);
+  int32_t Decode(const EncodedImage& encoded_frame,
+                      bool /* missing_frames */,
+                      const CodecSpecificInfo* /* codec_specific_info */,
+                      int64_t /* render_time_ms */) override {
+    if (fwrite(encoded_frame._buffer, 1, encoded_frame._length, file_)
+        < encoded_frame._length) {
+      RTC_LOG_ERR(LS_ERROR) << "fwrite of encoded frame failed.";
+      return WEBRTC_VIDEO_CODEC_ERROR;
+    }
+    return WEBRTC_VIDEO_CODEC_OK;
   }
 
  private:
@@ -252,19 +260,14 @@
   receive_config.renderer = &file_passthrough;
 
   VideoReceiveStream::Decoder decoder;
-  std::unique_ptr<DecoderBitstreamFileWriter> bitstream_writer;
-  if (!flags::DecoderBitstreamFilename().empty()) {
-    bitstream_writer.reset(new DecoderBitstreamFileWriter(
-        flags::DecoderBitstreamFilename().c_str()));
-    receive_config.pre_decode_callback = bitstream_writer.get();
-  }
   decoder =
       test::CreateMatchingDecoder(flags::MediaPayloadType(), flags::Codec());
   if (!flags::DecoderBitstreamFilename().empty()) {
-    // Replace with a null decoder if we're writing the bitstream to a file
+    // Replace decoder with file writer if we're writing the bitstream to a file
     // instead.
     delete decoder.decoder;
-    decoder.decoder = new test::FakeNullDecoder();
+    decoder.decoder = new DecoderBitstreamFileWriter(
+        flags::DecoderBitstreamFilename().c_str());
   }
   receive_config.decoders.push_back(decoder);
 
diff --git a/video/video_quality_test.cc b/video/video_quality_test.cc
index 3dbff9f..c12212e 100644
--- a/video/video_quality_test.cc
+++ b/video/video_quality_test.cc
@@ -97,7 +97,8 @@
 
 class VideoAnalyzer : public PacketReceiver,
                       public Transport,
-                      public rtc::VideoSinkInterface<VideoFrame> {
+                      public rtc::VideoSinkInterface<VideoFrame>,
+                      public EncodedFrameObserver {
  public:
   VideoAnalyzer(test::LayerFilteringTransport* transport,
                 const std::string& test_label,
@@ -129,7 +130,6 @@
         selected_sl_(selected_sl),
         selected_tl_(selected_tl),
         pre_encode_proxy_(this),
-        encode_timing_proxy_(this),
         last_fec_bytes_(0),
         frames_to_process_(duration_frames),
         frames_recorded_(0),
@@ -279,7 +279,8 @@
     }
   }
 
-  void PostEncodeFrameCallback(const EncodedFrame& encoded_frame) {
+  // EncodedFrameObserver implementation, wired to post_encode_callback.
+  void EncodedFrameCallback(const EncodedFrame& encoded_frame) override {
     rtc::CritScope lock(&crit_);
     if (!first_sent_timestamp_ &&
         encoded_frame.stream_id_ == selected_stream_) {
@@ -419,7 +420,6 @@
   rtc::VideoSinkInterface<VideoFrame>* pre_encode_proxy() {
     return &pre_encode_proxy_;
   }
-  EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; }
 
   void StartMeasuringCpuProcessTime() {
     rtc::CritScope lock(&cpu_measurement_lock_);
@@ -529,20 +529,6 @@
     double ssim;
   };
 
-  // This class receives the send-side OnEncodeTiming and is provided to not
-  // conflict with the receiver-side pre_decode_callback.
-  class OnEncodeTimingProxy : public EncodedFrameObserver {
-   public:
-    explicit OnEncodeTimingProxy(VideoAnalyzer* parent) : parent_(parent) {}
-
-    void EncodedFrameCallback(const EncodedFrame& frame) override {
-      parent_->PostEncodeFrameCallback(frame);
-    }
-
-   private:
-    VideoAnalyzer* const parent_;
-  };
-
   // This class receives the send-side OnFrame callback and is provided to not
   // conflict with the receiver-side renderer callback.
   class PreEncodeProxy : public rtc::VideoSinkInterface<VideoFrame> {
@@ -1000,7 +986,6 @@
   const int selected_sl_;
   const int selected_tl_;
   PreEncodeProxy pre_encode_proxy_;
-  OnEncodeTimingProxy encode_timing_proxy_;
   std::vector<Sample> samples_ RTC_GUARDED_BY(comparison_lock_);
   test::Statistics sender_time_ RTC_GUARDED_BY(comparison_lock_);
   test::Statistics receiver_time_ RTC_GUARDED_BY(comparison_lock_);
@@ -2007,8 +1992,7 @@
         analyzer.get();
     video_send_configs_[0].pre_encode_callback = analyzer->pre_encode_proxy();
     RTC_DCHECK(!video_send_configs_[0].post_encode_callback);
-    video_send_configs_[0].post_encode_callback =
-        analyzer->encode_timing_proxy();
+    video_send_configs_[0].post_encode_callback = analyzer.get();
 
     CreateFlexfecStreams();
     CreateVideoStreams();
diff --git a/video/video_receive_stream.cc b/video/video_receive_stream.cc
index 3b3d84f..3c10c4e 100644
--- a/video/video_receive_stream.cc
+++ b/video/video_receive_stream.cc
@@ -324,11 +324,6 @@
   if (codec_specific_info->codecType == kVideoCodecVP8) {
     simulcast_idx = codec_specific_info->codecSpecific.VP8.simulcastIdx;
   }
-  if (config_.pre_decode_callback) {
-    config_.pre_decode_callback->EncodedFrameCallback(EncodedFrame(
-        encoded_image._buffer, encoded_image._length, encoded_image._frameType,
-        simulcast_idx, encoded_image._timeStamp));
-  }
   {
     rtc::CritScope lock(&ivf_writer_lock_);
     if (ivf_writer_.get()) {