Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
22ade186
提交
22ade186
authored
5月 13, 2015
作者:
Anthony Minessale
提交者:
Michael Jerris
5月 28, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-7519: add abndwidth params and fix issue on reset of mov_avcodec
上级
e050d63e
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
99 行增加
和
24 行删除
+99
-24
mod_avcodec.c
src/mod/codecs/mod_avcodec/mod_avcodec.c
+99
-24
没有找到文件。
src/mod/codecs/mod_avcodec/mod_avcodec.c
浏览文件 @
22ade186
...
...
@@ -43,7 +43,7 @@
#include <x264.h>
#endif
#define FPS
15
// frame rate
#define FPS
30
// frame rate
SWITCH_MODULE_LOAD_FUNCTION
(
mod_avcodec_load
);
SWITCH_MODULE_DEFINITION
(
mod_avcodec
,
mod_avcodec_load
,
NULL
,
NULL
);
...
...
@@ -99,6 +99,11 @@ typedef struct h264_codec_context_s {
x264_nal_t
*
x264_nals
;
int
x264_nal_count
;
int
cur_nalu_index
;
int
change_bandwidth
;
unsigned
int
bandwidth
;
switch_codec_settings_t
codec_settings
;
#endif
}
h264_codec_context_t
;
...
...
@@ -109,17 +114,47 @@ static switch_status_t init_x264(h264_codec_context_t *context, uint32_t width,
{
x264_t
*
xh
=
context
->
x264_handle
;
x264_param_t
*
xp
=
&
context
->
x264_params
;
int
ret
=
0
;
//int ret = 0;
if
(
width
&&
height
)
{
context
->
codec_settings
.
video
.
width
=
width
;
context
->
codec_settings
.
video
.
height
=
height
;
}
if
(
!
context
->
codec_settings
.
video
.
width
)
{
context
->
codec_settings
.
video
.
width
=
1280
;
}
if
(
!
context
->
codec_settings
.
video
.
height
)
{
context
->
codec_settings
.
video
.
height
=
720
;
}
if
(
context
->
codec_settings
.
video
.
bandwidth
)
{
context
->
bandwidth
=
context
->
codec_settings
.
video
.
bandwidth
;
}
else
{
context
->
bandwidth
=
context
->
codec_settings
.
video
.
width
*
context
->
codec_settings
.
video
.
height
/
1024
;
}
if
(
context
->
bandwidth
>
5120
)
{
context
->
bandwidth
=
5120
;
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"initializing x264 handle %dx%d bw:%d
\n
"
,
width
,
height
,
context
->
bandwidth
);
if
(
xh
)
{
x
p
->
i_width
=
width
;
xp
->
i_height
=
height
;
ret
=
x264_encoder_reconfig
(
xh
,
xp
);
x
264_encoder_close
(
context
->
x264_handle
)
;
context
->
x264_handle
=
xh
=
NULL
;
switch_buffer_zero
(
context
->
nalu_buffer
);
if
(
ret
==
0
)
return
SWITCH_STATUS_SUCCESS
;
//xp->i_width = width;
//xp->i_height = height;
//ret = x264_encoder_reconfig(xh, xp);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"Cannot Reset error:%d
\n
"
,
ret
);
return
SWITCH_STATUS_FALSE
;
//if (ret == 0) return SWITCH_STATUS_SUCCESS;
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot Reset error:%d\n", ret);
//return SWITCH_STATUS_FALSE;
}
// x264_param_default(xp);
...
...
@@ -129,8 +164,8 @@ static switch_status_t init_x264(h264_codec_context_t *context, uint32_t width,
// xp->i_threads = 1;//X264_SYNC_LOOKAHEAD_AUTO;
// xp->i_lookahead_threads = X264_SYNC_LOOKAHEAD_AUTO;
// Video Properties
xp
->
i_width
=
width
;
xp
->
i_height
=
height
;
xp
->
i_width
=
context
->
codec_settings
.
video
.
width
;
xp
->
i_height
=
context
->
codec_settings
.
video
.
height
;
xp
->
i_frame_total
=
0
;
xp
->
i_keyint_max
=
FPS
*
10
;
// Bitstream parameters
...
...
@@ -145,10 +180,10 @@ static switch_status_t init_x264(h264_codec_context_t *context, uint32_t width,
// xp->i_log_level = X264_LOG_DEBUG;
xp
->
i_log_level
=
X264_LOG_NONE
;
// Rate control Parameters
xp
->
rc
.
i_bitrate
=
378
;
//kbps
xp
->
rc
.
i_bitrate
=
context
->
bandwidth
;
// Muxing parameters
xp
->
i_fps_den
=
1
;
xp
->
i_fps_num
=
FPS
;
//
xp->i_fps_den = 1;
//
xp->i_fps_num = FPS;
xp
->
i_timebase_den
=
xp
->
i_fps_num
;
xp
->
i_timebase_num
=
xp
->
i_fps_den
;
xp
->
i_slice_max_size
=
SLICE_SIZE
;
...
...
@@ -210,7 +245,7 @@ static switch_status_t nalu_slice(h264_codec_context_t *context, switch_frame_t
static
uint8_t
ff_input_buffer_padding
[
FF_INPUT_BUFFER_PADDING_SIZE
]
=
{
0
};
static
void
buffer_h264_nalu
(
h264_codec_context_t
*
context
,
switch_frame_t
*
frame
)
static
switch_status_t
buffer_h264_nalu
(
h264_codec_context_t
*
context
,
switch_frame_t
*
frame
)
{
uint8_t
nalu_type
=
0
;
uint8_t
*
data
=
frame
->
data
;
...
...
@@ -224,8 +259,7 @@ static void buffer_h264_nalu(h264_codec_context_t *context, switch_frame_t *fram
if
(
!
context
->
got_pps
&&
nalu_type
!=
7
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"waiting pps
\n
"
);
switch_set_flag
(
frame
,
SFF_WAIT_KEY_FRAME
);
return
;
return
SWITCH_STATUS_RESTART
;
}
if
(
!
context
->
got_pps
)
context
->
got_pps
=
1
;
...
...
@@ -239,7 +273,7 @@ static void buffer_h264_nalu(h264_codec_context_t *context, switch_frame_t *fram
nalu_type
=
*
(
data
+
1
)
&
0x1f
;
if
(
start
&&
end
)
return
;
if
(
start
&&
end
)
return
SWITCH_STATUS_RESTART
;
if
(
start
)
{
if
(
context
->
nalu_28_start
)
{
...
...
@@ -249,7 +283,7 @@ static void buffer_h264_nalu(h264_codec_context_t *context, switch_frame_t *fram
}
else
if
(
end
)
{
context
->
nalu_28_start
=
0
;
}
else
if
(
!
context
->
nalu_28_start
)
{
return
;
return
SWITCH_STATUS_RESTART
;
}
if
(
start
)
{
...
...
@@ -272,6 +306,8 @@ static void buffer_h264_nalu(h264_codec_context_t *context, switch_frame_t *fram
switch_buffer_write
(
buffer
,
ff_input_buffer_padding
,
sizeof
(
ff_input_buffer_padding
));
context
->
nalu_28_start
=
0
;
}
return
SWITCH_STATUS_SUCCESS
;
}
#ifndef H264_CODEC_USE_LIBX264
...
...
@@ -356,7 +392,7 @@ static switch_status_t open_encoder(h264_codec_context_t *context, uint32_t widt
context
->
encoder_ctx
->
width
=
width
;
context
->
encoder_ctx
->
height
=
height
;
/* frames per second */
context
->
encoder_ctx
->
time_base
=
(
AVRational
){
1
,
FPS
};
context
->
encoder_ctx
->
time_base
=
(
AVRational
){
1
,
90000
};
context
->
encoder_ctx
->
gop_size
=
FPS
*
3
;
/* emit one intra frame every 3 seconds */
context
->
encoder_ctx
->
max_b_frames
=
0
;
context
->
encoder_ctx
->
pix_fmt
=
AV_PIX_FMT_YUV420P
;
...
...
@@ -394,6 +430,11 @@ static switch_status_t switch_h264_init(switch_codec_t *codec, switch_codec_flag
switch_assert
(
context
);
memset
(
context
,
0
,
sizeof
(
*
context
));
if
(
codec_settings
)
{
context
->
codec_settings
=
*
codec_settings
;
}
if
(
decoding
)
{
context
->
decoder
=
avcodec_find_decoder
(
AV_CODEC_ID_H264
);
...
...
@@ -589,17 +630,25 @@ static switch_status_t switch_h264_encode(switch_codec_t *codec,
switch_image_t
*
img
=
frame
->
img
;
void
*
encoded_data
=
frame
->
data
;
uint32_t
*
encoded_data_len
=
&
frame
->
datalen
;
unsigned
int
*
flag
=
&
frame
->
flags
;
//
unsigned int *flag = &frame->flags;
if
(
*
flag
&
SFF_WAIT_KEY_FRAME
)
context
->
need_key_frame
=
1
;
//
if (*flag & SFF_WAIT_KEY_FRAME) context->need_key_frame = 1;
//if (*encoded_data_len < SWITCH_DEFAULT_VIDEO_SIZE) return SWITCH_STATUS_FALSE;
if
(
!
context
)
return
SWITCH_STATUS_FALSE
;
if
(
context
->
change_bandwidth
)
{
context
->
codec_settings
.
video
.
bandwidth
=
context
->
change_bandwidth
;
context
->
change_bandwidth
=
0
;
init_x264
(
context
,
0
,
0
);
switch_set_flag
(
frame
,
SFF_WAIT_KEY_FRAME
);
}
if
(
!
context
->
x264_handle
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"initializing x264 handle %dx%d
\n
"
,
width
,
height
);
init_x264
(
context
,
width
,
height
);
switch_set_flag
(
frame
,
SFF_WAIT_KEY_FRAME
);
}
if
(
frame
->
flags
&
SFF_SAME_IMAGE
)
{
...
...
@@ -613,6 +662,7 @@ static switch_status_t switch_h264_encode(switch_codec_t *codec,
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"picture size changed from %dx%d to %dx%d, reinitializing encoder
\n
"
,
context
->
x264_params
.
i_width
,
context
->
x264_params
.
i_width
,
width
,
height
);
init_x264
(
context
,
width
,
height
);
switch_set_flag
(
frame
,
SFF_WAIT_KEY_FRAME
);
}
switch_assert
(
encoded_data
);
...
...
@@ -673,6 +723,7 @@ static switch_status_t switch_h264_decode(switch_codec_t *codec, switch_frame_t
{
h264_codec_context_t
*
context
=
(
h264_codec_context_t
*
)
codec
->
private_info
;
AVCodecContext
*
avctx
=
context
->
decoder_ctx
;
switch_status_t
status
;
switch_assert
(
frame
);
...
...
@@ -688,7 +739,14 @@ static switch_status_t switch_h264_decode(switch_codec_t *codec, switch_frame_t
context
->
last_received_timestamp
=
frame
->
timestamp
;
context
->
last_received_complete_picture
=
frame
->
m
?
SWITCH_TRUE
:
SWITCH_FALSE
;
buffer_h264_nalu
(
context
,
frame
);
status
=
buffer_h264_nalu
(
context
,
frame
);
if
(
status
==
SWITCH_STATUS_RESTART
)
{
switch_set_flag
(
frame
,
SFF_WAIT_KEY_FRAME
);
switch_buffer_zero
(
context
->
nalu_buffer
);
context
->
nalu_28_start
=
0
;
return
SWITCH_STATUS_MORE_DATA
;
}
if
(
frame
->
m
)
{
uint32_t
size
=
switch_buffer_inuse
(
context
->
nalu_buffer
);
...
...
@@ -760,6 +818,23 @@ static switch_status_t switch_h264_control(switch_codec_t *codec,
case
SCC_VIDEO_REFRESH
:
context
->
need_key_frame
=
1
;
break
;
case
SCC_VIDEO_BANDWIDTH
:
{
switch
(
ctype
)
{
case
SCCT_INT
:
context
->
change_bandwidth
=
*
((
int
*
)
cmd_data
);
break
;
case
SCCT_STRING
:
{
char
*
bwv
=
(
char
*
)
cmd_data
;
context
->
change_bandwidth
=
switch_parse_bandwidth_string
(
bwv
);
}
break
;
default:
break
;
}
}
break
;
default:
break
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论