Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2013-11-24 18:55:39 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ca6720aab2b90f32a193cf0ba3bf8f5d1438f7da
ca6720aa
1 parent
38539431
add time to write ts file
显示空白字符变更
内嵌
并排对比
正在显示
7 个修改的文件
包含
71 行增加
和
62 行删除
trunk/src/core/srs_core_codec.cpp
trunk/src/core/srs_core_codec.hpp
trunk/src/core/srs_core_hls.cpp
trunk/src/core/srs_core_hls.hpp
trunk/src/core/srs_core_protocol.hpp
trunk/src/core/srs_core_source.cpp
trunk/src/core/srs_core_source.hpp
trunk/src/core/srs_core_codec.cpp
查看文件 @
ca6720a
...
...
@@ -46,8 +46,12 @@ void SrsCodecSample::clear()
cts
=
0
;
frame_type
=
SrsCodecVideoAVCFrameReserved
;
codec_id
=
SrsCodecVideoReserved
;
avc_packet_type
=
SrsCodecVideoAVCTypeReserved
;
sound_rate
=
SrsCodecAudioSampleRateReserved
;
sound_size
=
SrsCodecAudioSampleSizeReserved
;
sound_type
=
SrsCodecAudioSoundTypeReserved
;
aac_packet_type
=
SrsCodecAudioTypeReserved
;
}
int
SrsCodecSample
::
add_sample
(
char
*
bytes
,
int
size
)
...
...
@@ -79,9 +83,6 @@ SrsCodec::SrsCodec()
video_codec_id
=
0
;
audio_data_rate
=
0
;
audio_codec_id
=
0
;
sound_rate
=
0
;
sound_size
=
0
;
sound_type
=
0
;
profile
=
0
;
level
=
0
;
avc_extra_size
=
0
;
...
...
@@ -124,12 +125,15 @@ int SrsCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample)
int8_t
sound_format
=
stream
->
read_1bytes
();
sound_type
=
sound_format
&
0x01
;
sound_size
=
(
sound_format
>>
1
)
&
0x01
;
sound_rate
=
(
sound_format
>>
2
)
&
0x01
;
int8_t
sound_type
=
sound_format
&
0x01
;
int8_t
sound_size
=
(
sound_format
>>
1
)
&
0x01
;
int8_t
sound_rate
=
(
sound_format
>>
2
)
&
0x01
;
sound_format
=
(
sound_format
>>
4
)
&
0x0f
;
audio_codec_id
=
sound_format
;
sample
->
sound_type
=
(
SrsCodecAudioSoundType
)
sound_type
;
sample
->
sound_rate
=
(
SrsCodecAudioSampleRate
)
sound_rate
;
sample
->
sound_size
=
(
SrsCodecAudioSampleSize
)
sound_size
;
// only support aac
if
(
audio_codec_id
!=
SrsCodecAudioAAC
)
{
...
...
@@ -145,6 +149,7 @@ int SrsCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample)
}
int8_t
aac_packet_type
=
stream
->
read_1bytes
();
sample
->
aac_packet_type
=
(
SrsCodecAudioType
)
aac_packet_type
;
if
(
aac_packet_type
==
SrsCodecAudioTypeSequenceHeader
)
{
// AudioSpecificConfig
...
...
@@ -206,7 +211,6 @@ int SrsCodec::video_avc_demux(int8_t* data, int size, SrsCodecSample* sample)
frame_type
=
(
frame_type
>>
4
)
&
0x0f
;
sample
->
frame_type
=
(
SrsCodecVideoAVCFrame
)
frame_type
;
sample
->
codec_id
=
(
SrsCodecVideo
)
codec_id
;
// only support h.264/avc
if
(
codec_id
!=
SrsCodecVideoAVC
)
{
...
...
trunk/src/core/srs_core_codec.hpp
查看文件 @
ca6720a
...
...
@@ -132,6 +132,7 @@ enum SrsCodecAudio
// 1 = AAC raw
enum
SrsCodecAudioType
{
SrsCodecAudioTypeReserved
=
-
1
,
SrsCodecAudioTypeSequenceHeader
=
0
,
SrsCodecAudioTypeRawData
=
1
,
};
...
...
@@ -143,6 +144,8 @@ enum SrsCodecAudioType
// 3 = 44 kHz = 44100 Hz
enum
SrsCodecAudioSampleRate
{
SrsCodecAudioSampleRateReserved
=
-
1
,
SrsCodecAudioSampleRate5512
=
0
,
SrsCodecAudioSampleRate11025
=
1
,
SrsCodecAudioSampleRate22050
=
2
,
...
...
@@ -156,6 +159,8 @@ enum SrsCodecAudioSampleRate
// 1 = 16-bit samples
enum
SrsCodecAudioSampleSize
{
SrsCodecAudioSampleSizeReserved
=
-
1
,
SrsCodecAudioSampleSize8bit
=
0
,
SrsCodecAudioSampleSize16bit
=
1
,
};
...
...
@@ -165,6 +170,8 @@ enum SrsCodecAudioSampleSize
// 1 = Stereo sound
enum
SrsCodecAudioSoundType
{
SrsCodecAudioSoundTypeReserved
=
-
1
,
SrsCodecAudioSoundTypeMono
=
0
,
SrsCodecAudioSoundTypeStereo
=
1
,
};
...
...
@@ -188,12 +195,17 @@ public:
SrsCodecBuffer
buffers
[
SRS_MAX_CODEC_SAMPLE
];
public
:
bool
is_video
;
// video specified
SrsCodecVideoAVCFrame
frame_type
;
SrsCodecVideoAVCType
avc_packet_type
;
// CompositionTime, video_file_format_spec_v10_1.pdf, page 78.
// cts = pts - dts, where dts = flvheader->timestamp.
int32_t
cts
;
SrsCodecVideoAVCFrame
frame_type
;
SrsCodecVideo
codec_id
;
SrsCodecVideoAVCType
avc_packet_type
;
// audio specified
SrsCodecAudioSampleRate
sound_rate
;
SrsCodecAudioSampleSize
sound_size
;
SrsCodecAudioSoundType
sound_type
;
SrsCodecAudioType
aac_packet_type
;
public
:
SrsCodecSample
();
virtual
~
SrsCodecSample
();
...
...
@@ -230,12 +242,6 @@ public:
*/
// @see: SrsCodecAudioType
int
audio_codec_id
;
// @see: SrsCodecAudioSampleRate
int
sound_rate
;
// @see: SrsCodecAudioSampleSize
int
sound_size
;
// @see: SrsCodecAudioSoundType
int
sound_type
;
int
audio_data_rate
;
// in bps
// the avc extra data, the AVC sequence header,
// without the flv codec header,
...
...
trunk/src/core/srs_core_hls.cpp
查看文件 @
ca6720a
...
...
@@ -139,41 +139,11 @@ int SrsHLS::on_meta_data(SrsOnMetaDataPacket* metadata)
if
((
prop
=
obj
->
get_property
(
"audiodatarate"
))
!=
NULL
&&
prop
->
is_number
())
{
codec
->
audio_data_rate
=
(
int
)(
1000
*
srs_amf0_convert
<
SrsAmf0Number
>
(
prop
)
->
value
);
}
if
((
prop
=
obj
->
get_property
(
"audiosamplerate"
))
!=
NULL
&&
prop
->
is_number
())
{
int
sound_rate
=
(
int
)
srs_amf0_convert
<
SrsAmf0Number
>
(
prop
)
->
value
;
if
(
sound_rate
==
5512
)
{
codec
->
sound_rate
=
SrsCodecAudioSampleRate5512
;
}
else
if
(
sound_rate
==
11025
)
{
codec
->
sound_rate
=
SrsCodecAudioSampleRate11025
;
}
else
if
(
sound_rate
==
22050
)
{
codec
->
sound_rate
=
SrsCodecAudioSampleRate22050
;
}
else
if
(
sound_rate
==
44100
)
{
codec
->
sound_rate
=
SrsCodecAudioSampleRate44100
;
}
else
{
ret
=
ERROR_HLS_METADATA
;
srs_error
(
"invalid sound_rate of metadata: %d, ret=%d"
,
sound_rate
,
ret
);
return
ret
;
}
}
if
((
prop
=
obj
->
get_property
(
"audiosamplesize"
))
!=
NULL
&&
prop
->
is_number
())
{
int
sound_size
=
(
int
)
srs_amf0_convert
<
SrsAmf0Number
>
(
prop
)
->
value
;
if
(
sound_size
==
16
)
{
codec
->
sound_size
=
SrsCodecAudioSampleSize16bit
;
}
else
if
(
sound_size
==
8
)
{
codec
->
sound_size
=
SrsCodecAudioSampleSize8bit
;
}
else
{
ret
=
ERROR_HLS_METADATA
;
srs_error
(
"invalid sound_size of metadata: %d, ret=%d"
,
sound_size
,
ret
);
return
ret
;
}
}
if
((
prop
=
obj
->
get_property
(
"stereo"
))
!=
NULL
&&
prop
->
is_number
())
{
if
(
srs_amf0_convert
<
SrsAmf0Boolean
>
(
prop
)
->
value
)
{
codec
->
sound_type
=
SrsCodecAudioSoundTypeStereo
;
}
else
{
codec
->
sound_type
=
SrsCodecAudioSoundTypeMono
;
}
}
// ignore the following, for each flv/rtmp packet contains them:
// audiosamplerate, sample->sound_rate
// audiosamplesize, sample->sound_size
// stereo, sample->sound_type
return
ret
;
}
...
...
@@ -196,7 +166,15 @@ int SrsHLS::on_audio(SrsCommonMessage* audio)
return
ret
;
}
if
((
ret
=
muxer
->
write
(
codec
,
sample
))
!=
ERROR_SUCCESS
)
{
// ignore sequence header
if
(
sample
->
aac_packet_type
==
SrsCodecAudioTypeSequenceHeader
)
{
return
ret
;
}
u_int32_t
timestamp
=
audio
->
header
.
timestamp
;
// TODO: correct the timestamp.
if
((
ret
=
muxer
->
write_audio
(
timestamp
,
codec
,
sample
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
@@ -221,7 +199,15 @@ int SrsHLS::on_video(SrsCommonMessage* video)
return
ret
;
}
if
((
ret
=
muxer
->
write
(
codec
,
sample
))
!=
ERROR_SUCCESS
)
{
// ignore sequence header
if
(
sample
->
frame_type
==
SrsCodecVideoAVCFrameKeyFrame
&&
sample
->
avc_packet_type
==
SrsCodecVideoAVCTypeSequenceHeader
)
{
return
ret
;
}
u_int32_t
timestamp
=
video
->
header
.
timestamp
;
// TODO: correct the timestamp.
if
((
ret
=
muxer
->
write_video
(
timestamp
,
codec
,
sample
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
@@ -229,7 +215,7 @@ int SrsHLS::on_video(SrsCommonMessage* video)
}
// @see: ngx_rtmp_mpegts_header
static
u_char
mpegts_header
[]
=
{
u_int8_t
mpegts_header
[]
=
{
/* TS */
0x47
,
0x40
,
0x00
,
0x10
,
0x00
,
/* PSI */
...
...
@@ -329,9 +315,21 @@ int SrsTSMuxer::open(std::string _path)
return
ret
;
}
int
SrsTSMuxer
::
write
(
SrsCodec
*
codec
,
SrsCodecSample
*
sample
)
int
SrsTSMuxer
::
write
_audio
(
u_int32_t
time
,
SrsCodec
*
codec
,
SrsCodecSample
*
sample
)
{
int
ret
=
ERROR_SUCCESS
;
static
u_int8_t
packet
[
188
];
return
ret
;
}
int
SrsTSMuxer
::
write_video
(
u_int32_t
time
,
SrsCodec
*
codec
,
SrsCodecSample
*
sample
)
{
int
ret
=
ERROR_SUCCESS
;
static
u_int8_t
packet
[
188
];
return
ret
;
}
...
...
trunk/src/core/srs_core_hls.hpp
查看文件 @
ca6720a
...
...
@@ -66,7 +66,8 @@ public:
virtual
~
SrsTSMuxer
();
public
:
virtual
int
open
(
std
::
string
_path
);
virtual
int
write
(
SrsCodec
*
codec
,
SrsCodecSample
*
sample
);
virtual
int
write_audio
(
u_int32_t
time
,
SrsCodec
*
codec
,
SrsCodecSample
*
sample
);
virtual
int
write_video
(
u_int32_t
time
,
SrsCodec
*
codec
,
SrsCodecSample
*
sample
);
virtual
void
close
();
};
...
...
trunk/src/core/srs_core_protocol.hpp
查看文件 @
ca6720a
...
...
@@ -199,7 +199,7 @@ struct SrsMessageHeader
* The 4 bytes are packed in the big-endian order.
* @remark, used as calc timestamp when decode and encode time.
*/
int32_t
timestamp
;
u_
int32_t
timestamp
;
SrsMessageHeader
();
virtual
~
SrsMessageHeader
();
...
...
trunk/src/core/srs_core_source.cpp
查看文件 @
ca6720a
...
...
@@ -192,7 +192,7 @@ int SrsConsumer::jitter_correct(SrsSharedPtrMessage* msg, int audio_sample_rate,
* 3. last_pkt_correct_time: simply add the positive delta,
* and enforce the time monotonically.
*/
int32_t
time
=
msg
->
header
.
timestamp
;
u_
int32_t
time
=
msg
->
header
.
timestamp
;
int32_t
delta
=
time
-
last_pkt_time
;
// if jitter detected, reset the delta.
...
...
@@ -207,7 +207,7 @@ int SrsConsumer::jitter_correct(SrsSharedPtrMessage* msg, int audio_sample_rate,
}
// sometimes, the time is absolute time, so correct it again.
if
(
delta
>
CONST_MAX_JITTER_MS
)
{
if
(
delta
<
0
||
delta
>
CONST_MAX_JITTER_MS
)
{
delta
=
DEFAULT_FRAME_TIME_MS
;
}
...
...
trunk/src/core/srs_core_source.hpp
查看文件 @
ca6720a
...
...
@@ -46,8 +46,8 @@ class SrsHLS;
class
SrsConsumer
{
private
:
int32_t
last_pkt_time
;
int32_t
last_pkt_correct_time
;
u_int32_t
last_pkt_time
;
u_int32_t
last_pkt_correct_time
;
SrsSource
*
source
;
std
::
vector
<
SrsSharedPtrMessage
*>
msgs
;
bool
paused
;
...
...
请
注册
或
登录
后发表评论