Skip to content

Commit 0db02b9

Browse files
committed
Refactoring dec/enc
1 parent 148a603 commit 0db02b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1180
-692
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ project(VideoStreamer)
44

55
set(CMAKE_CXX_STANDARD 17)
66
set(CMAKE_INCLUDE_CURRENT_DIR ON)
7+
set(Boost_USE_STATIC_LIBS ON)
78

89
if(WIN32)
910
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
@@ -22,8 +23,8 @@ executable(${PROJECT_NAME}
2223
SOURCES "src/"
2324
THREADS
2425
CONAN_MODULES toml11 ffmpeg
25-
BOOST program_options
26-
MODULES GSL http_streamer)
26+
# BOOST program_options
27+
MODULES http_streamer GSL)
2728

2829
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
2930

config.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[http_streamer]
2-
url = "https://192.168.1.144:5000"
2+
url = "http://192.168.1.144:5000"
33
cert = "/home/pi/cert/kovalenko.crt"
44
key = "/home/pi/cert/kovalenko.key"
5+
log_level = "DEBUG"
56

67
[inputs]
78
items = [
8-
{ id = "video1", type = "WebCamera", url = "/dev/video1", hw_name = "", hw_id = 0 }
9+
{ id = "video1", input_format = "v4l2", url = "/dev/video1", hw_name = "", hw_id = 0, options = { "video_size" = "1280x720", "framerate" = "10", "pixel_format" = "mjpeg" }}
910
]

modules/http_streamer/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ project(http_streamer)
55
set(CMAKE_CXX_STANDARD 17)
66
set(CMAKE_INCLUDE_CURRENT_DIR ON)
77

8-
shared_library(${PROJECT_NAME}
8+
if(WIN32)
9+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
10+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
11+
endif()
12+
13+
static_library(${PROJECT_NAME}
914
SOURCES "src/"
1015
THREADS
11-
CONAN_MODULES ffmpeg
12-
#BOOST system
16+
CONAN_MODULES toml11 ffmpeg
1317
MODULES GSL)
1418

1519
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)

modules/http_streamer/include/FFmpegInput.h

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
#include "../src/InputConfig.h"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
#include "../src/InputVideoStream.h"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
#include "../src/StreamChannel.h"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include "AVMemory.h"
2+
#include "FFmpeg.h"
3+
4+
namespace video_streamer
5+
{
6+
7+
namespace
8+
{
9+
10+
void freeAVFormatContext(AVFormatContext* formatContext)
11+
{
12+
avformat_free_context(formatContext);
13+
}
14+
15+
void freeAVCodecContext(AVCodecContext* codecContext)
16+
{
17+
avcodec_free_context(&codecContext);
18+
}
19+
20+
void freeAVPacket(AVPacket* packet)
21+
{
22+
av_packet_unref(packet);
23+
av_packet_free(&packet);
24+
}
25+
26+
void freeAVFrame(AVFrame* frame)
27+
{
28+
av_frame_unref(frame);
29+
av_frame_free(&frame);
30+
}
31+
32+
void freeAVBufferRef(AVBufferRef* bufferRef)
33+
{
34+
av_buffer_unref(&bufferRef);
35+
}
36+
37+
} // anonymous
38+
39+
AVUniquePtr<AVFormatContext> makeAVFormatContext()
40+
{
41+
return makeAVUniquePtr<AVFormatContext>(&avformat_alloc_context, &freeAVFormatContext);
42+
}
43+
44+
AVUniquePtr<AVCodecContext> makeAVCodecContext(const AVCodec *codec)
45+
{
46+
return makeAVUniquePtr<AVCodecContext>(
47+
std::bind(&avcodec_alloc_context3, codec), &freeAVCodecContext);
48+
}
49+
50+
AVUniquePtr<AVPacket> makeAVPacket()
51+
{
52+
return makeAVUniquePtr<AVPacket>(&av_packet_alloc, &freeAVPacket);
53+
}
54+
55+
AVUniquePtr<AVFrame> makeAVFrame()
56+
{
57+
return makeAVUniquePtr<AVFrame>(&av_frame_alloc, &freeAVFrame);
58+
}
59+
60+
AVUniquePtr<AVBufferRef> makeHWFrameCtx(AVBufferRef* bufferRef)
61+
{
62+
return makeAVUniquePtr<AVBufferRef>(
63+
std::bind(&av_hwframe_ctx_alloc, bufferRef), &freeAVBufferRef);
64+
}
65+
66+
} // video_streamer
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <functional>
5+
6+
struct AVFormatContext;
7+
struct AVCodecContext;
8+
struct AVCodec;
9+
struct AVPacket;
10+
struct AVFrame;
11+
struct AVBufferRef;
12+
13+
namespace video_streamer
14+
{
15+
16+
template <typename T>
17+
using AVUniquePtr = std::unique_ptr<T, std::function<void(T*)>>;
18+
19+
template <typename T, typename AllocateFunc, typename Deleter>
20+
AVUniquePtr<T> makeAVUniquePtr(AllocateFunc allocateFunc, Deleter deleter)
21+
{
22+
AVUniquePtr<T> ptr(nullptr, deleter);
23+
ptr.reset(allocateFunc());
24+
return ptr;
25+
}
26+
27+
AVUniquePtr<AVFormatContext> makeAVFormatContext();
28+
AVUniquePtr<AVCodecContext> makeAVCodecContext(const AVCodec *codec);
29+
AVUniquePtr<AVPacket> makeAVPacket();
30+
AVUniquePtr<AVFrame> makeAVFrame();
31+
AVUniquePtr<AVBufferRef> makeHWFrameCtx(AVBufferRef* bufferRef);
32+
33+
} // video_streamer

0 commit comments

Comments
 (0)