xref: /aosp_15_r20/external/webrtc/test/pc/e2e/analyzer/video/video_dumping.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef TEST_PC_E2E_ANALYZER_VIDEO_VIDEO_DUMPING_H_
12 #define TEST_PC_E2E_ANALYZER_VIDEO_VIDEO_DUMPING_H_
13 
14 #include <memory>
15 #include <string>
16 
17 #include "absl/strings/string_view.h"
18 #include "api/test/video/video_frame_writer.h"
19 #include "api/video/video_frame.h"
20 #include "api/video/video_sink_interface.h"
21 #include "test/testsupport/video_frame_writer.h"
22 
23 namespace webrtc {
24 namespace webrtc_pc_e2e {
25 
26 // `VideoSinkInterface` to dump incoming video frames into specified video
27 // writer.
28 class VideoWriter final : public rtc::VideoSinkInterface<VideoFrame> {
29  public:
30   // Creates video writer. Caller keeps ownership of `video_writer` and is
31   // responsible for closing it after VideoWriter will be destroyed.
32   VideoWriter(test::VideoFrameWriter* video_writer, int sampling_modulo);
33   VideoWriter(const VideoWriter&) = delete;
34   VideoWriter& operator=(const VideoWriter&) = delete;
35   ~VideoWriter() override = default;
36 
37   void OnFrame(const VideoFrame& frame) override;
38 
39  private:
40   test::VideoFrameWriter* const video_writer_;
41   const int sampling_modulo_;
42 
43   int64_t frames_counter_ = 0;
44 };
45 
46 // Creates a `VideoFrameWriter` to dump video frames together with their ids.
47 // It uses provided `video_writer_delegate` to write video itself. Frame ids
48 // will be logged into the specified file.
49 std::unique_ptr<test::VideoFrameWriter> CreateVideoFrameWithIdsWriter(
50     std::unique_ptr<test::VideoFrameWriter> video_writer_delegate,
51     absl::string_view frame_ids_dump_file_name);
52 
53 }  // namespace webrtc_pc_e2e
54 }  // namespace webrtc
55 
56 #endif  // TEST_PC_E2E_ANALYZER_VIDEO_VIDEO_DUMPING_H_
57