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
/*
* Copyright 2025 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "api/video/video_frame_buffer.h"
#include "api/video/i420_buffer.h"
namespace livekit {
// Pixel format of the DMA buffer surface.
enum class DmaBufPixelFormat {
kNV12 = 0,
kYUV420M = 1,
};
// A VideoFrameBuffer backed by a Jetson NvBufSurface DMA file descriptor.
// Reports Type::kNative so it flows through the standard WebRTC pipeline.
// The encoder can detect this type and pass the fd directly to the hardware
// encoder via V4L2_MEMORY_DMABUF for zero-copy encoding.
class DmaBufVideoFrameBuffer : public webrtc::VideoFrameBuffer {
public:
DmaBufVideoFrameBuffer(int dmabuf_fd,
int width,
int height,
DmaBufPixelFormat pixel_format);
~DmaBufVideoFrameBuffer() override = default;
// webrtc::VideoFrameBuffer
Type type() const override;
int width() const override;
int height() const override;
webrtc::scoped_refptr<webrtc::I420BufferInterface> ToI420() override;
webrtc::scoped_refptr<webrtc::VideoFrameBuffer> CropAndScale(
int offset_x,
int offset_y,
int crop_width,
int crop_height,
int scaled_width,
int scaled_height) override;
// DMA buffer accessors
int dmabuf_fd() const { return dmabuf_fd_; }
DmaBufPixelFormat pixel_format() const { return pixel_format_; }
// Helper to check if a VideoFrameBuffer is a DmaBufVideoFrameBuffer.
static DmaBufVideoFrameBuffer* FromNative(webrtc::VideoFrameBuffer* buffer);
private:
int dmabuf_fd_;
int width_;
int height_;
DmaBufPixelFormat pixel_format_;
};
} // namespace livekit