正在显示
3 个修改的文件
包含
34 行增加
和
34 行删除
| @@ -157,18 +157,9 @@ int main(int argc, char** argv) | @@ -157,18 +157,9 @@ int main(int argc, char** argv) | ||
| 157 | goto rtmp_destroy; | 157 | goto rtmp_destroy; |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | - // convert the h264 packet to rtmp packet. | ||
| 161 | - char* rtmp_data = NULL; | ||
| 162 | - int rtmp_size = 0; | ||
| 163 | - u_int32_t timestamp = 0; | ||
| 164 | - if (srs_h264_to_rtmp(data, size, dts, pts, &rtmp_data, &rtmp_size, ×tamp) != 0) { | ||
| 165 | - srs_trace("h264 raw data to rtmp data failed."); | ||
| 166 | - goto rtmp_destroy; | ||
| 167 | - } | ||
| 168 | - | ||
| 169 | - // send out the rtmp packet. | ||
| 170 | - int type = SRS_RTMP_TYPE_VIDEO; | ||
| 171 | - if (srs_write_packet(rtmp, type, timestamp, rtmp_data, rtmp_size) != 0) { | 160 | + // send out the h264 packet over RTMP |
| 161 | + if (srs_write_h264_raw_frame(rtmp, data, size, dts, pts) != 0) { | ||
| 162 | + srs_trace("send h264 raw data failed."); | ||
| 172 | goto rtmp_destroy; | 163 | goto rtmp_destroy; |
| 173 | } | 164 | } |
| 174 | 165 | ||
| @@ -176,7 +167,7 @@ int main(int argc, char** argv) | @@ -176,7 +167,7 @@ int main(int argc, char** argv) | ||
| 176 | // H.264-AVC-ISO_IEC_14496-10.pdf, page 44. | 167 | // H.264-AVC-ISO_IEC_14496-10.pdf, page 44. |
| 177 | u_int8_t nut = (char)data[0] & 0x1f; | 168 | u_int8_t nut = (char)data[0] & 0x1f; |
| 178 | srs_trace("sent packet: type=%s, time=%d, size=%d, fps=%d, b[0]=%#x(%s)", | 169 | srs_trace("sent packet: type=%s, time=%d, size=%d, fps=%d, b[0]=%#x(%s)", |
| 179 | - srs_type2string(type), timestamp, rtmp_size, fps, nut, | 170 | + srs_type2string(SRS_RTMP_TYPE_VIDEO), dts, size, fps, nut, |
| 180 | (nut == 7? "SPS":(nut == 8? "PPS":(nut == 5? "I":(nut == 1? "P":"Unknown"))))); | 171 | (nut == 7? "SPS":(nut == 8? "PPS":(nut == 5? "I":(nut == 1? "P":"Unknown"))))); |
| 181 | 172 | ||
| 182 | // @remark, when use encode device, it not need to sleep. | 173 | // @remark, when use encode device, it not need to sleep. |
| @@ -70,6 +70,9 @@ struct Context | @@ -70,6 +70,9 @@ struct Context | ||
| 70 | SimpleSocketStream* skt; | 70 | SimpleSocketStream* skt; |
| 71 | int stream_id; | 71 | int stream_id; |
| 72 | 72 | ||
| 73 | + // for h264 raw stream | ||
| 74 | + SrsStream raw_stream; | ||
| 75 | + | ||
| 73 | Context() { | 76 | Context() { |
| 74 | rtmp = NULL; | 77 | rtmp = NULL; |
| 75 | skt = NULL; | 78 | skt = NULL; |
| @@ -996,22 +999,31 @@ char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize) | @@ -996,22 +999,31 @@ char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize) | ||
| 996 | return any->human_print(pdata, psize); | 999 | return any->human_print(pdata, psize); |
| 997 | } | 1000 | } |
| 998 | 1001 | ||
| 999 | -int srs_h264_to_rtmp(char* h264_raw_data, int h264_raw_size, u_int32_t dts, u_int32_t pts, char** prtmp_data, int* prtmp_size, u_int32_t* ptimestamp) | 1002 | +int srs_write_h264_raw_frame(srs_rtmp_t rtmp, char* frame, int frame_size, u_int32_t dts, u_int32_t pts) |
| 1000 | { | 1003 | { |
| 1001 | - srs_assert(h264_raw_size > 0); | 1004 | + int ret = ERROR_SUCCESS; |
| 1005 | + | ||
| 1006 | + srs_assert(frame_size > 0); | ||
| 1002 | 1007 | ||
| 1003 | - // the timestamp in rtmp message header is dts. | ||
| 1004 | - *ptimestamp = dts; | 1008 | + srs_assert(rtmp != NULL); |
| 1009 | + Context* context = (Context*)rtmp; | ||
| 1010 | + | ||
| 1011 | + if ((ret = context->raw_stream.initialize(frame, frame_size)) != ERROR_SUCCESS) { | ||
| 1012 | + return ret; | ||
| 1013 | + } | ||
| 1014 | + | ||
| 1015 | + | ||
| 1016 | + /*// the timestamp in rtmp message header is dts. | ||
| 1017 | + u_int32_t timestamp = dts; | ||
| 1005 | 1018 | ||
| 1006 | // for h264 in RTMP video payload, there is 5bytes header: | 1019 | // for h264 in RTMP video payload, there is 5bytes header: |
| 1007 | // 1bytes, FrameType | CodecID | 1020 | // 1bytes, FrameType | CodecID |
| 1008 | // 1bytes, AVCPacketType | 1021 | // 1bytes, AVCPacketType |
| 1009 | // 3bytes, CompositionTime, the cts. | 1022 | // 3bytes, CompositionTime, the cts. |
| 1010 | // @see: E.4.3 Video Tags, video_file_format_spec_v10_1.pdf, page 78 | 1023 | // @see: E.4.3 Video Tags, video_file_format_spec_v10_1.pdf, page 78 |
| 1011 | - *prtmp_size = h264_raw_size + 5; | ||
| 1012 | - char* p = new char[*prtmp_size]; | ||
| 1013 | - memcpy(p + 5, h264_raw_data, h264_raw_size); | ||
| 1014 | - *prtmp_data = p; | 1024 | + int size = h264_raw_size + 5; |
| 1025 | + char* data = new char[size]; | ||
| 1026 | + memcpy(data + 5, h264_raw_data, h264_raw_size); | ||
| 1015 | 1027 | ||
| 1016 | // 5bits, 7.3.1 NAL unit syntax, | 1028 | // 5bits, 7.3.1 NAL unit syntax, |
| 1017 | // H.264-AVC-ISO_IEC_14496-10.pdf, page 44. | 1029 | // H.264-AVC-ISO_IEC_14496-10.pdf, page 44. |
| @@ -1044,9 +1056,9 @@ int srs_h264_to_rtmp(char* h264_raw_data, int h264_raw_size, u_int32_t dts, u_in | @@ -1044,9 +1056,9 @@ int srs_h264_to_rtmp(char* h264_raw_data, int h264_raw_size, u_int32_t dts, u_in | ||
| 1044 | char* pp = (char*)&cts; | 1056 | char* pp = (char*)&cts; |
| 1045 | *p++ = pp[2]; | 1057 | *p++ = pp[2]; |
| 1046 | *p++ = pp[1]; | 1058 | *p++ = pp[1]; |
| 1047 | - *p++ = pp[0]; | 1059 | + *p++ = pp[0];*/ |
| 1048 | 1060 | ||
| 1049 | - return 0; | 1061 | + return ret; |
| 1050 | } | 1062 | } |
| 1051 | 1063 | ||
| 1052 | int srs_h264_startswith_annexb(char* h264_raw_data, int h264_raw_size, int* pnb_start_code) | 1064 | int srs_h264_startswith_annexb(char* h264_raw_data, int h264_raw_size, int* pnb_start_code) |
| @@ -337,24 +337,21 @@ extern char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize); | @@ -337,24 +337,21 @@ extern char* srs_amf0_human_print(srs_amf0_t amf0, char** pdata, int* psize); | ||
| 337 | ************************************************************** | 337 | ************************************************************** |
| 338 | *************************************************************/ | 338 | *************************************************************/ |
| 339 | /** | 339 | /** |
| 340 | -* convert h264 stream data to rtmp packet. | ||
| 341 | -* @param h264_raw_data the input h264 raw data, a encoded h.264 I/P/B frame data. | ||
| 342 | -* @paam h264_raw_size the size of h264 raw data. assert > 0. | 340 | +* write h.264 raw frame to rtmp server. |
| 341 | +* @param frame the input h264 raw data, an encoded h.264 I/P/B frame data. | ||
| 342 | +* it must be prefixed by h.264 annexb format, by N[00] 00 00 01, where N>=0, | ||
| 343 | +* for instance, 00 00 00 01 67 42 80 29 95 A0 14 01 6E 40 | ||
| 344 | +* @paam frame_size the size of h264 raw data. assert frame_size > 0. | ||
| 343 | * @param dts the dts of h.264 raw data. | 345 | * @param dts the dts of h.264 raw data. |
| 344 | * @param pts the pts of h.264 raw data. | 346 | * @param pts the pts of h.264 raw data. |
| 345 | -* @param prtmp_data the output rtmp format packet, which can be send by srs_write_packet. | ||
| 346 | -* @param prtmp_size the size of rtmp packet, for srs_write_packet. | ||
| 347 | -* @param ptimestamp the timestamp of rtmp packet, for srs_write_packet. | ||
| 348 | * | 347 | * |
| 349 | -* @remark, user should free the h264_raw_data. | ||
| 350 | -* @remark, user should free the prtmp_data if success. | 348 | +* @remark, user should free the frame. |
| 351 | * @remark, the tbn of dts/pts is 1/1000 for RTMP, that is, in ms. | 349 | * @remark, the tbn of dts/pts is 1/1000 for RTMP, that is, in ms. |
| 352 | * | 350 | * |
| 353 | * @return 0, success; otherswise, failed. | 351 | * @return 0, success; otherswise, failed. |
| 354 | */ | 352 | */ |
| 355 | -extern int srs_h264_to_rtmp( | ||
| 356 | - char* h264_raw_data, int h264_raw_size, u_int32_t dts, u_int32_t pts, | ||
| 357 | - char** prtmp_data, int* prtmp_size, u_int32_t* ptimestamp | 353 | +extern int srs_write_h264_raw_frame(srs_rtmp_t rtmp, |
| 354 | + char* frame, int frame_size, u_int32_t dts, u_int32_t pts | ||
| 358 | ); | 355 | ); |
| 359 | /** | 356 | /** |
| 360 | * whether h264 raw data starts with the annexb, | 357 | * whether h264 raw data starts with the annexb, |
-
请 注册 或 登录 后发表评论