Commit 32e8d7cf authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Merge branch 'remote_drive' into 'master'

Added the repaet header feature to the hardware h264 encoder.

See merge request !1
parents 9d266011 cb3ebe82
......@@ -12,6 +12,7 @@ extern "C"
#include <libavutil/timestamp.h>
#include <libavutil/opt.h>
#include <libswresample/swresample.h>
#include <libswscale/swscale.h>
}
#include "portaudio.h"
......@@ -20,7 +21,7 @@ extern "C"
#include <chrono>
#define NUM_VIDEO_BUFFERS 4
#define NUM_AUDIO_BUFFERS 4
#define NUM_AUDIO_BUFFERS 8
typedef struct{
void *start;
......@@ -36,7 +37,9 @@ typedef struct{
AVStream *stream;
AVCodecContext *encoder_context;
AVFrame *frame;
AVFrame *tmp_frame;
int64_t next_pts;
struct SwsContext *resampler;
// device data
int fd;
TVideoBuffer *buffers;
......@@ -49,6 +52,7 @@ typedef struct{
unsigned int height;
float framerate;
unsigned int format;
AVPixelFormat av_format;
// device data
unsigned char device[32];
// encoder
......@@ -60,6 +64,14 @@ typedef struct{
unsigned int av_profile;
}TVideoConfig;
typedef struct
{
unsigned char **data;
unsigned int num_bytes;
long long frame_time;
int64_t frame_pts;
}TAudioBuffer;
typedef struct{
unsigned long int av_channels_layout;
PaSampleFormat pa_sample_format;
......@@ -71,15 +83,16 @@ typedef struct{
AVCodecContext *encoder_context;
AVFrame *frame;
AVFrame *tmp_frame;
int64_t next_pts;
int nb_samples;
struct SwrContext *resampler;
int samples_count;
int nb_samples;
// device data
PaStream *audio_stream;
CMutex access;
long long frame_time;
std::chrono::time_point<std::chrono::high_resolution_clock> start_time;
int64_t next_pts;
TAudioBuffer *buffers;
unsigned int buffer_write;
unsigned int buffer_read;
}TAudioData;
typedef struct{
......@@ -94,7 +107,9 @@ typedef struct{
}TAudioConfig;
typedef struct{
bool video_enable;
TVideoConfig video;
bool audio_enable;
TAudioConfig audio;
unsigned char srt_ip[15];
unsigned int srt_port;
......@@ -148,7 +163,7 @@ class CStreamSrtSource
static int audioCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void *userData);
static void *capture_audio_thread(void *param);
public:
CStreamSrtSource();
CStreamSrtSource(const std::string &name);
void load_config(const std::string &filename);
void load_config(TStreamConfig &stream_config);
void save_config(const std::string &filename);
......
......@@ -13,10 +13,11 @@ set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/opt/vc/lib/pkgconfig/")
pkg_search_module(AVCODEC REQUIRED libavcodec)
pkg_search_module(AVDEVICE REQUIRED libavdevice)
pkg_search_module(AVFILTER REQUIRED libavfilter)
pkg_search_module(AVAVFORMAT REQUIRED libavformat)
pkg_search_module(AVFORMAT REQUIRED libavformat)
pkg_search_module(AVUTIL REQUIRED libavutil)
pkg_search_module(SWRESAMPLE REQUIRED libswresample)
pkg_search_module(MMAL REQUIRED mmal)
pkg_search_module(SWSCALE REQUIRED libswscale)
pkg_search_module(MMAL mmal)
pkg_search_module(PORTAUDIO REQUIRED portaudiocpp)
find_package(iriutils REQUIRED)
......@@ -29,16 +30,19 @@ include_directories(${AVFILTER_INCLUDE_DIRS})
include_directories(${AVFORMAT_INCLUDE_DIRS})
include_directories(${AVUTIL_INCLUDE_DIRS})
include_directories(${SWRESAMPLE_INCLUDE_DIRS})
include_directories(${SWSCALE_INCLUDE_DIRS})
include_directories(${MMAL_INCLUDE_DIRS})
include_directories(${PORTAUDIO_INCLUDE_DIRS})
include_directories(${iriutils_INCLUDE_DIR})
message(${AVCODEC_LIBRARY_DIRS})
link_directories(${AVCODEC_LIBRARY_DIRS})
link_directories(${AVDEVICE_LIBRARY_DIRS})
link_directories(${AVFILTER_LIBRARY_DIRS})
link_directories(${AVFORMAT_LIBRARY_DIRS})
link_directories(${AVUTIL_LIBRARY_DIRS})
link_directories(${SWRESAMPLE_LIBRARY_DIRS})
link_directories(${SWSCALE_LIBRARY_DIRS})
link_directories(${MMAL_LIBRARY_DIRS})
link_directories(${PORTAUDIO_LIBRARY_DIRS})
......@@ -57,6 +61,7 @@ target_link_libraries(${PROJECT_NAME} ${AVFILTER_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${AVFORMAT_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${AVUTIL_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${SWRESAMPLE_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${SWSCALE_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${MMAL_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${PORTAUDIO_LIBRARIES})
......@@ -66,6 +71,7 @@ target_link_libraries(${PROJECT_NAME} ${AVFILTER_LDFLAGS_OTHER})
target_link_libraries(${PROJECT_NAME} ${AVFORMAT_LDFLAGS_OTHER})
target_link_libraries(${PROJECT_NAME} ${AVUTIL_LDFLAGS_OTHER})
target_link_libraries(${PROJECT_NAME} ${SWRESAMPLE_LDFLAGS_OTHER})
target_link_libraries(${PROJECT_NAME} ${SWSCALE_LDFLAGS_OTHER})
#ADD_DEPENDENCIES(${PROJECT_NAME} my_example_library_target)
ADD_DEPENDENCIES(${PROJECT_NAME} xsd_files_gen)
......
......@@ -7,9 +7,15 @@
int main(int argc, char **argv)
{
try{
CStreamSrtSource stream;
CStreamSrtSource stream("stream");
stream.load_config("../src/xml/stream_config.xml");
if(argc!=2)
{
std::cout << "Invalid numbe of arguments:" << std::endl;
std::cout << " " << argv[0] << " <XML configuration file>" << std::endl;
return 0;
}
stream.load_config(std::string(argv[1]));
stream.start();
sleep(1000000);
stream.stop();
......
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<stream_config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="stream_config_cfg_file.xsd">
<video_enable>true</video_enable>
<video_config>
<video_device>/dev/video0</video_device>
<width>1280</width>
<height>720</height>
<height>960</height>
<framerate>30</framerate>
<format>YUV420</format>
<format>RGB24</format>
<encoder>
<bitrate>6000000</bitrate>
<variable_bitrate>true</variable_bitrate>
......@@ -14,6 +15,7 @@
<profile>high</profile>
</encoder>
</video_config>
<audio_enable>false</audio_enable>
<audio_config>
<audio_device>hw:0,0</audio_device>
<num_channels>2</num_channels>
......
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<stream_config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="stream_config_cfg_file.xsd">
<video_enable>true</video_enable>
<video_config>
<video_device>/dev/video1</video_device>
<width>1024</width>
<height>768</height>
<framerate>30</framerate>
<format>RGB24</format>
<encoder>
<bitrate>6000000</bitrate>
<variable_bitrate>true</variable_bitrate>
<i_frame_period>10</i_frame_period>
<level>4</level>
<profile>high</profile>
</encoder>
</video_config>
<audio_enable>false</audio_enable>
<audio_config>
<audio_device>hw:0,0</audio_device>
<num_channels>2</num_channels>
<sample_rate>48000</sample_rate>
<sample_format>S32</sample_format>
<bitrate>32000</bitrate>
</audio_config>
<srt_ip/>
<srt_port>9999</srt_port>
</stream_config>
......@@ -48,7 +48,7 @@
</xsd:element>
<xsd:element name="sample_rate" type="xsd:int">
</xsd:element>
<xsd:element name="sample_format" type="audio_format">
<xsd:element name="sample_format" type="xsd:string">
</xsd:element>
<xsd:element name="bitrate" type="xsd:float">
</xsd:element>
......@@ -57,8 +57,12 @@
<xsd:complexType name="stream_config_t">
<xsd:sequence>
<xsd:element name="video_enable" type="xsd:boolean">
</xsd:element>
<xsd:element name="video_config" type="video_config_t">
</xsd:element>
<xsd:element name="audio_enable" type="xsd:boolean">
</xsd:element>
<xsd:element name="audio_config" type="audio_config_t">
</xsd:element>
<xsd:element name="srt_ip" type="IPv4Address" minOccurs="0">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment