winlin

for bug #66, refine the api and demo.

... ... @@ -37,26 +37,30 @@ gcc srs_h264_raw_publish.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_h
#define srs_trace(msg, ...) printf(msg, ##__VA_ARGS__);printf("\n")
int read_h264_frame(char* data, int size, char** p, int fps,
int read_h264_frame(char* data, int size, char** pp, int fps,
char** frame, int* frame_size, int* dts, int* pts)
{
char* p = *pp;
// @remark, for this demo, to publish h264 raw file to SRS,
// we search the h264 frame from the buffer which cached the h264 data.
// please get h264 raw data from device, it always a encoded frame.
int pnb_start_code = 0;
if (!srs_h264_startswith_annexb(*p, size - (*p - data), &pnb_start_code)) {
if (!srs_h264_startswith_annexb(p, size - (p - data), &pnb_start_code)) {
srs_trace("h264 raw data invalid.");
return -1;
}
*p += pnb_start_code;
p += pnb_start_code;
*frame = *p;
for (;*p < data + size; *p = *p + 1) {
if (srs_h264_startswith_annexb(*p, size - (*p - data), &pnb_start_code)) {
*frame = p;
for (;p < data + size; p++) {
if (srs_h264_startswith_annexb(p, size - (p - data), &pnb_start_code)) {
break;
}
}
*frame_size = *p - *frame;
*pp = p;
*frame_size = p - *frame;
if (*frame_size <= 0) {
srs_trace("h264 raw data invalid.");
return -1;
... ... @@ -167,7 +171,7 @@ int main(int argc, char** argv)
// H.264-AVC-ISO_IEC_14496-10.pdf, page 44.
u_int8_t nut = (char)data[0] & 0x1f;
srs_trace("sent packet: type=%s, time=%d, size=%d, fps=%d, b[0]=%#x(%s)",
srs_type2string(SRS_RTMP_TYPE_VIDEO), dts, size, fps, nut,
srs_type2string(SRS_RTMP_TYPE_VIDEO), dts, size, fps, (char)data[0],
(nut == 7? "SPS":(nut == 8? "PPS":(nut == 5? "I":(nut == 1? "P":"Unknown")))));
// @remark, when use encode device, it not need to sleep.
... ...
... ... @@ -70,9 +70,6 @@ struct Context
SimpleSocketStream* skt;
int stream_id;
// for h264 raw stream
SrsStream raw_stream;
Context() {
rtmp = NULL;
skt = NULL;
... ... @@ -1003,15 +1000,15 @@ int srs_write_h264_raw_frame(srs_rtmp_t rtmp, char* frame, int frame_size, u_int
{
int ret = ERROR_SUCCESS;
srs_assert(frame_size > 0);
srs_assert(frame_size > 1);
srs_assert(rtmp != NULL);
Context* context = (Context*)rtmp;
if ((ret = context->raw_stream.initialize(frame, frame_size)) != ERROR_SUCCESS) {
return ret;
}
// 5bits, 7.3.1 NAL unit syntax,
// H.264-AVC-ISO_IEC_14496-10.pdf, page 44.
// 7: SPS, 8: PPS, 5: I Frame, 1: P Frame
u_int8_t nal_unit_type = (char)frame[0] & 0x1f;
/*// the timestamp in rtmp message header is dts.
u_int32_t timestamp = dts;
... ... @@ -1025,11 +1022,6 @@ int srs_write_h264_raw_frame(srs_rtmp_t rtmp, char* frame, int frame_size, u_int
char* data = new char[size];
memcpy(data + 5, h264_raw_data, h264_raw_size);
// 5bits, 7.3.1 NAL unit syntax,
// H.264-AVC-ISO_IEC_14496-10.pdf, page 44.
// 7: SPS, 8: PPS, 5: I Frame, 1: P Frame
u_int8_t nal_unit_type = (char)h264_raw_data[0] & 0x1f;
// Frame Type, Type of video frame.
// @see: E.4.3 Video Tags, video_file_format_spec_v10_1.pdf, page 78
int8_t frame_type = SrsCodecVideoAVCFrameInterFrame;
... ...
... ... @@ -337,11 +337,12 @@ extern char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize);
**************************************************************
*************************************************************/
/**
* write h.264 raw frame to rtmp server.
* write h.264 raw frame over RTMP to rtmp server.
* @param frame the input h264 raw data, an encoded h.264 I/P/B frame data.
* it must be prefixed by h.264 annexb format, by N[00] 00 00 01, where N>=0,
* for instance, 00 00 00 01 67 42 80 29 95 A0 14 01 6E 40
* @paam frame_size the size of h264 raw data. assert frame_size > 0.
* the frame without h.264 annexb header, by N[00] 00 00 01, where N>=0,
* for instance, header(00 00 00 01) + frame(67 42 80 29 95 A0 14 01 6E 40)
* @paam frame_size the size of h264 raw data.
* assert frame_size > 1, at least has 1 bytes header.
* @param dts the dts of h.264 raw data.
* @param pts the pts of h.264 raw data.
*
... ...