-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathrtmp_streaming.cpp
More file actions
97 lines (77 loc) · 3.09 KB
/
rtmp_streaming.cpp
File metadata and controls
97 lines (77 loc) · 3.09 KB
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
#include <set>
#include <map>
#include <memory>
#include <iostream>
#include <chrono>
#include <stdlib.h>
#include <math.h>
#include <cstdio>
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include "streamer.hpp"
namespace py = pybind11;
using namespace pybind11::literals;
using namespace streamer;
void print_shape(const char *array_name, const py::array &array)
{
printf("%s shape: [", array_name);
//py::buffer_info info = array.request();
int nd = array.ndim();
for(int i=0;i<nd;i++) {
printf("%ld ", array.shape()[i]);
}
printf("]\n");
}
class PythonStreamer : public Streamer
{
public:
void stream_frame(const py::array &frame)
{
//print_shape("frame", frame);
py::buffer_info info = frame.request();
Streamer::stream_frame(reinterpret_cast<const uint8_t*>(info.ptr));
}
void stream_frame_with_duration(const py::array &frame, int64_t frame_duration)
{
py::buffer_info info = frame.request();
Streamer::stream_frame(reinterpret_cast<const uint8_t*>(info.ptr), frame_duration);
}
void stream_frame_audio(const py::array &frame)
{
//print_shape("frame", frame);
py::buffer_info info = frame.request();
Streamer::stream_frame_audio(reinterpret_cast<const uint8_t*>(info.ptr));
}
void stream_frame_audio_with_duration(const py::array &frame, int64_t frame_duration)
{
py::buffer_info info = frame.request();
Streamer::stream_frame_audio(reinterpret_cast<const uint8_t*>(info.ptr), frame_duration);
}
};
PYBIND11_MODULE(rtmp_streaming, m)
{
m.doc() = "streaming from python";
py::class_<StreamerConfig>(m, "StreamerConfig")
.def(py::init<>())
.def(py::init<int, int, int, int, int, int,
const std::string &,int,int,
const std::string &>())
.def_readwrite("source_width", &StreamerConfig::src_width)
.def_readwrite("source_height", &StreamerConfig::src_height)
.def_readwrite("stream_width", &StreamerConfig::dst_width)
.def_readwrite("stream_height", &StreamerConfig::dst_height)
.def_readwrite("stream_fps", &StreamerConfig::fps)
.def_readwrite("stream_bitrate", &StreamerConfig::bitrate)
.def_readwrite("stream_profile", &StreamerConfig::profile)
.def_readwrite("audio_channel", &StreamerConfig::audio_channel)
.def_readwrite("sample_rate", &StreamerConfig::sample_rate)
.def_readwrite("stream_server", &StreamerConfig::server);
py::class_<PythonStreamer>(m, "Streamer")
.def(py::init<>())
.def("init", &PythonStreamer::init)
.def("enable_av_debug_log", &PythonStreamer::enable_av_debug_log)
.def("stream_frame", &PythonStreamer::stream_frame)
.def("stream_frame_with_duration", &PythonStreamer::stream_frame_with_duration)
.def("stream_frame_audio", &PythonStreamer::stream_frame_audio)
.def("stream_frame_audio_with_duration", &PythonStreamer::stream_frame_audio_with_duration);
}