rtpdump.cpp
资源名称:chapter15.rar [点击查看]
上传用户:hjq518
上传日期:2021-12-09
资源大小:5084k
文件大小:2k
源码类别:
Audio
开发平台:
Visual C++
- // rtpdump.cpp : Defines the entry point for the console application.
- //
- #include "StdAfx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <memory.h>
- #ifdef WIN32
- #include <Winsock2.h>
- #else
- #include <netinet/in.h>
- #endif
- int main(int argc, char* argv[])
- {
- unsigned int bufsize, pacno=0, temp32;
- unsigned short temp16;
- unsigned char buf[65000];
- int i, intime;
- FILE *f;
- if (argc != 2)
- {
- printf ("Usage: %s <H.264 RTP packet file>n", argv[0]);
- return -1;
- }
- if (NULL == (f = fopen (argv[1], "rb")))
- {
- printf ("%s: cannot open H.264 packet file %s for readingn", argv[0], argv[1]);
- return -2;
- }
- while (1)
- {
- if (4 != fread (&bufsize, 1, 4, f))
- return 0;
- if (4 != fread (&intime, 1, 4, f))
- {
- printf ("Panic, cannot read timestamp, old software version file?n");
- return -1;
- }
- printf ("nnpacket #%4d containing %5d bytesn", pacno++, bufsize);
- if (bufsize != fread (buf, 1, bufsize, f))
- {
- printf ("Problems while reading buffer, exitn");
- return -3;
- }
- for (i=0; i< 25; i++)
- printf ("%02x ", buf[i]);
- printf ("n");
- printf ("Version (V): %dn", (buf[0] >> 6) & 0x03);
- printf ("Padding (P): %dn", (buf[0] >> 5) & 0x01);
- printf ("Extension (X): %dn", (buf[0] >> 4) & 0x01);
- printf ("CSRC count (CC): %dn", (buf[0] >> 0) & 0x0F);
- printf ("Marker bit (M): %dn", (buf[1] >> 7) & 0x01);
- printf ("Payload Type (PT): %dn", (buf[1] >> 0) & 0x7F);
- memcpy (&temp16, &buf[2], 2);
- printf ("Sequence Number: %dn", ntohs(temp16));
- memcpy (&temp32, &buf[4], 4);
- printf ("Timestamp: %dn", ntohl(temp32));
- memcpy (&temp32, &buf[8], 4);
- printf ("SSRC: %dn", ntohl(temp32));
- printf ("First Byte: 0x%xn", buf[12]);
- }
- }