2007-09-14 21:40:52 +00:00
|
|
|
|
/*
|
|
|
|
|
* tvheadend, RTP interface
|
|
|
|
|
* Copyright (C) 2007 Andreas <EFBFBD>man
|
|
|
|
|
*
|
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
|
|
#include "tvhead.h"
|
|
|
|
|
#include "channels.h"
|
|
|
|
|
#include "rtp.h"
|
|
|
|
|
#include "dispatch.h"
|
|
|
|
|
|
|
|
|
|
#include <ffmpeg/avformat.h>
|
|
|
|
|
#include <ffmpeg/random.h>
|
|
|
|
|
|
2007-10-27 07:40:30 +00:00
|
|
|
|
//static int64_t lts;
|
|
|
|
|
//static int pkts;
|
2007-09-14 21:40:52 +00:00
|
|
|
|
|
2007-10-27 07:40:30 +00:00
|
|
|
|
void
|
|
|
|
|
rtp_output_ts(void *opaque, struct th_subscription *s,
|
|
|
|
|
uint8_t *pkt, int blocks, int64_t pcr)
|
2007-09-14 21:40:52 +00:00
|
|
|
|
{
|
2007-10-27 07:40:30 +00:00
|
|
|
|
th_rtp_streamer_t *trs = opaque;
|
|
|
|
|
struct msghdr msg;
|
|
|
|
|
struct iovec vec[2];
|
|
|
|
|
int r;
|
2007-09-14 21:40:52 +00:00
|
|
|
|
|
2007-10-27 07:40:30 +00:00
|
|
|
|
AVRational mpeg_tc = {1, 90000};
|
|
|
|
|
char hdr[12];
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
int64_t ts;
|
|
|
|
|
ts = getclock_hires();
|
|
|
|
|
pkts++;
|
|
|
|
|
|
|
|
|
|
if(ts - lts > 100000) {
|
|
|
|
|
printf("%d packet per sec\n", pkts * 10);
|
|
|
|
|
pkts = 0;
|
|
|
|
|
lts = ts;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2007-09-14 21:40:52 +00:00
|
|
|
|
|
2007-10-27 07:40:30 +00:00
|
|
|
|
pcr = av_rescale_q(pcr, AV_TIME_BASE_Q, mpeg_tc);
|
2007-09-14 21:40:52 +00:00
|
|
|
|
|
2007-10-27 07:40:30 +00:00
|
|
|
|
hdr[0] = 0x80;
|
|
|
|
|
hdr[1] = 33; /* M2TS */
|
|
|
|
|
hdr[2] = trs->trs_seq >> 8;
|
|
|
|
|
hdr[3] = trs->trs_seq;
|
2007-09-14 21:40:52 +00:00
|
|
|
|
|
2007-10-27 07:40:30 +00:00
|
|
|
|
hdr[4] = pcr >> 24;
|
|
|
|
|
hdr[5] = pcr >> 16;
|
|
|
|
|
hdr[6] = pcr >> 8;
|
|
|
|
|
hdr[7] = pcr;
|
2007-09-14 21:40:52 +00:00
|
|
|
|
|
2007-10-27 07:40:30 +00:00
|
|
|
|
hdr[8] = 0;
|
|
|
|
|
hdr[9] = 0;
|
|
|
|
|
hdr[10] = 0;
|
|
|
|
|
hdr[11] = 0;
|
2007-09-14 21:40:52 +00:00
|
|
|
|
|
|
|
|
|
|
2007-10-27 07:40:30 +00:00
|
|
|
|
vec[0].iov_base = hdr;
|
|
|
|
|
vec[0].iov_len = 12;
|
|
|
|
|
vec[1].iov_base = pkt;
|
|
|
|
|
vec[1].iov_len = blocks * 188;
|
2007-09-14 21:40:52 +00:00
|
|
|
|
|
2007-10-27 07:40:30 +00:00
|
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
|
msg.msg_name = &trs->trs_dest;
|
|
|
|
|
msg.msg_namelen = sizeof(struct sockaddr_in);
|
|
|
|
|
msg.msg_iov = vec;
|
|
|
|
|
msg.msg_iovlen = 2;
|
2007-09-14 21:40:52 +00:00
|
|
|
|
|
2007-10-27 07:40:30 +00:00
|
|
|
|
r = sendmsg(trs->trs_fd, &msg, 0);
|
|
|
|
|
if(r < 0)
|
|
|
|
|
perror("sendmsg");
|
2007-09-14 21:40:52 +00:00
|
|
|
|
|
2007-10-27 07:40:30 +00:00
|
|
|
|
trs->trs_seq++;
|
2007-09-14 21:40:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-10-27 07:40:30 +00:00
|
|
|
|
|
2007-09-14 21:40:52 +00:00
|
|
|
|
void
|
|
|
|
|
rtp_streamer_init(th_rtp_streamer_t *trs, int fd, struct sockaddr_in *dst)
|
|
|
|
|
{
|
|
|
|
|
trs->trs_fd = fd;
|
|
|
|
|
trs->trs_dest = *dst;
|
|
|
|
|
trs->trs_seq = 0;
|
|
|
|
|
}
|