Skip to content

Commit c468ec1

Browse files
committed
fixbug
1 parent e829dde commit c468ec1

5 files changed

Lines changed: 46 additions & 9 deletions

File tree

‎Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LIBS_poco = -lPocoXML -lPocoJSON -lPocoUtil -lPocoNet -lPocoFoundation
1414

1515
LIBS_DIR=-L./lib
1616

17+
#P_Macro=-DH264_TB=1024*1024*2 -DCAP_FPS=30 -DH264_IDR=5
1718
OPT=-O2 $(INC) -DSOCKLEN_T=socklen_t -DNO_SSTREAM=1 -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DC_DEBUG=0 -DCPP_DEBUG=0
1819

1920
CFLAGS =-Wall $(OPT)

‎src/exe/recorder.c‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
* Created on: Jan 28, 2015
55
* Author: ouyangfeng
66
*/
7+
#include <signal.h>
8+
79
#include "base/utils.h"
810
#include "media/videorecorder.h"
911

1012
long long t;
1113
int fps = 0;
14+
Video_Recorder *recorder = NULL;
1215

1316
void cdear(int type, void* cookie, void* data)
1417
{
@@ -19,25 +22,34 @@ void cdear(int type, void* cookie, void* data)
1922
else
2023
{
2124
printf("fps:%d\n", fps);
22-
fps = 0;
25+
fps = 1;
2326
t = current_time_m();
2427
}
2528

2629
}
2730

31+
/* 信号处理例程,其中dunno将会得到信号的值 */
32+
static void sigroutine(int dunno)
33+
{
34+
stop_video_recorder(recorder);
35+
free(recorder);
36+
recorder = NULL;
37+
return;
38+
}
39+
2840
void testCamera(void)
2941
{
30-
Video_Recorder* recorder = create_video_recorder(640, 480);
42+
recorder = create_video_recorder(640, 480);
3143
recorder->setDataCallBack(recorder, (void*) cdear, (void*) cdear);
3244
start_video_recorder(recorder);
33-
stop_video_recorder(recorder);
34-
free(recorder);
35-
recorder = NULL;
3645
}
3746

3847
int main(int argc, char **argv)
3948
{
4049
t = current_time_m();
50+
signal(SIGHUP, sigroutine); //* 下面设置三个信号的处理方法
51+
signal(SIGINT, sigroutine);
52+
signal(SIGQUIT, sigroutine);
4153
testCamera();
4254
return 1;
4355
}

‎src/exe/vlsave.cpp‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Created on: 2015年1月28日
55
* Author: maygolf
66
*/
7-
7+
#include <signal.h>
88
#include <stdio.h>
99
#include <iostream>
1010

@@ -16,6 +16,13 @@
1616
using namespace std;
1717
using namespace Poco;
1818

19+
int run = 1;
20+
/* 信号处理例程,其中dunno将会得到信号的值 */
21+
static void sigroutine(int dunno)
22+
{
23+
run = 0;
24+
}
25+
1926
int main(int argc, char **argv)
2027
{
2128

@@ -25,6 +32,10 @@ int main(int argc, char **argv)
2532
exit(0);
2633
}
2734

35+
signal(SIGHUP, sigroutine); //* 下面设置三个信号的处理方法
36+
signal(SIGINT, sigroutine);
37+
signal(SIGQUIT, sigroutine);
38+
2839
bool dfps = false;
2940
int postion = 0;
3041
if (argc == 4 && (string(argv[1]) == string("-f")))
@@ -49,7 +60,7 @@ int main(int argc, char **argv)
4960
{ 0x0, 0x0, 0x0, 0x1 };
5061
int time = LocalDateTime().second();
5162
int fps = 0;
52-
while (1)
63+
while (run)
5364
{
5465
nalu = reader.readH264();
5566
if (nalu != 0)
@@ -79,6 +90,9 @@ int main(int argc, char **argv)
7990
}
8091

8192
}
93+
94+
fclose(out);
95+
out = NULL;
8296
}
8397
else
8498
{

‎src/media/videorecorder.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ int start_video_recorder(Video_Recorder* recorder)
136136
// init base config param
137137
recorder->base_cfg.codectype = VENC_CODEC_H264;
138138

139-
recorder->base_cfg.framerate = 25;
139+
recorder->base_cfg.framerate = CAP_FPS;
140140
recorder->base_cfg.input_width = recorder->width;
141141
recorder->base_cfg.input_height = recorder->height;
142142
recorder->base_cfg.dst_width = recorder->width;
143143
recorder->base_cfg.dst_height = recorder->height;
144-
recorder->base_cfg.maxKeyInterval = 5;
144+
recorder->base_cfg.maxKeyInterval = H264_IDR;
145145
recorder->base_cfg.inputformat = VENC_PIXEL_YUV420; //uv combined
146146
recorder->base_cfg.targetbitrate = H264_TB;
147147

‎src/media/videorecorder.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ extern "C" {
3636
#define H264_TB 1024 * 1024
3737
#endif
3838

39+
//h264编码关键帧率 IDR
40+
#ifndef H264_IDR
41+
#define H264_IDR 5
42+
#endif
43+
44+
//V4L采集帧率
45+
#ifndef CAP_FPS
46+
#define CAP_FPS 30
47+
#endif
48+
3949
typedef void (*DataCallBack)(int type, void* cookie,void* data);
4050

4151
typedef struct Video_Recorder

0 commit comments

Comments
 (0)