-
Notifications
You must be signed in to change notification settings - Fork 9
/
rtp-h263.c
100 lines (88 loc) · 2.63 KB
/
rtp-h263.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (C) 2004 Nathan Lutchansky <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <errno.h>
#include <event.h>
#include <log.h>
#include <frame.h>
#include <stream.h>
#include <outputs.h>
#include <rtp.h>
#include <rtp_media.h>
#include <conf_parse.h>
struct rtp_h263 {
unsigned char *d;
int len;
int init_done;
int ts_incr;
unsigned int timestamp;
};
static int h263_process_frame( struct frame *f, void *d )
{
struct rtp_h263 *out = (struct rtp_h263 *)d;
/* Discard the first two bytes, which are both 0x00 */
out->d = f->d + 2;
out->len = f->length - 2;
out->timestamp += out->ts_incr;
return out->init_done;
}
static int h263_get_sdp( char *dest, int len, int payload, int port, void *d )
{
return snprintf( dest, len, "m=video %d RTP/AVP %d\r\na=rtpmap:%d H263-1998/90000\r\n", port, payload, payload );
}
static int h263_send( struct rtp_endpoint *ep, void *d )
{
struct rtp_h263 *out = (struct rtp_h263 *)d;
int i, plen;
struct iovec v[3];
unsigned char vhdr[2] = { 0x04, 0x00 }; /* Set P bit */
v[1].iov_base = vhdr;
v[1].iov_len = 2;
for( i = 0; i < out->len; i += plen )
{
plen = out->len - i;
if( plen > ep->max_data_size ) plen = ep->max_data_size;
v[2].iov_base = out->d + i;
v[2].iov_len = plen;
if( send_rtp_packet( ep, v, 3, out->timestamp,
plen + i == out->len ) < 0 )
return -1;
vhdr[0] = 0; /* clear P bit */
}
return 0;
}
struct rtp_media *new_rtp_media_h263_stream( struct stream *stream )
{
struct rtp_h263 *out;
int fincr, fbase;
stream->get_framerate( stream, &fincr, &fbase );
out = (struct rtp_h263 *)malloc( sizeof( struct rtp_h263 ) );
out->init_done = 1;
out->timestamp = 0;
out->ts_incr = 90000 * fincr / fbase;
return new_rtp_media( h263_get_sdp, NULL,
h263_process_frame, h263_send, out );
}