annotate libmpdemux/demux_nemesi.c @ 24787:02535b3216c5

Avoid text deformation and subtitles moving outside the screen in pan-and-scan mode. For this, crop amounts are passed from vo_gl as negative margins sizes. They are used to calculate aspect ratio. They are ignored when calculating subtitle positions, so subtitles will stay on screen most of the time. Based on a patch by Jindrich Makovicka [makovick gmail com].
author eugeni
date Fri, 19 Oct 2007 18:16:23 +0000
parents 17a83ea47ee1
children 2c790baff42c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24564
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
1 /*
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
2 * Copyright (C) 2007 Alessandro Molina <amol.wrk@gmail.com>
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
3 *
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
7 * (at your option) any later version.
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
8 *
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
12 * GNU General Public License for more details.
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
13 *
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
15 * along with MPlayer; if not, write to the Free Software Foundation,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
17 */
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
18
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
19 #include "demux_nemesi.h"
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
20 #include "stheader.h"
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
21 #define HAVE_STRUCT_SOCKADDR_STORAGE
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
22 #include "nemesi/rtsp.h"
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
23 #include "nemesi/rtp.h"
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
24
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
25 int rtsp_transport_tcp = 0;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
26 int rtsp_transport_sctp = 0;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
27 // extern int rtsp_port;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
28
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
29 typedef enum { NEMESI_SESSION_VIDEO,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
30 NEMESI_SESSION_AUDIO } Nemesi_SessionType;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
31
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
32 typedef struct {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
33 rtsp_ctrl * rtsp;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
34 rtp_session * session[2];
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
35 rtp_frame first_pkt[2];
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
36 double time[2];
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
37 double seek;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
38 } Nemesi_DemuxerStreamData;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
39
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
40 static void link_session_and_fetch_conf(Nemesi_DemuxerStreamData * ndsd,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
41 Nemesi_SessionType stype,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
42 rtp_session * sess,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
43 rtp_buff * buff, unsigned int * fps)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
44 {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
45 extern float force_fps;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
46 rtp_ssrc *ssrc;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
47 rtsp_ctrl * ctl = ndsd->rtsp;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
48 rtp_frame * fr = &ndsd->first_pkt[stype];
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
49 rtp_buff trash_buff;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
50
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
51 ndsd->session[stype] = sess;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
52
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
53 if (buff == NULL)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
54 buff = &trash_buff;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
55
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
56 if ( (buff != NULL) || (fps != NULL) ) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
57 rtp_fill_buffers(rtsp_get_rtp_th(ctl));
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
58 for (ssrc = rtp_active_ssrc_queue(rtsp_get_rtp_queue(ctl));
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
59 ssrc;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
60 ssrc = rtp_next_active_ssrc(ssrc)) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
61 if (ssrc->rtp_sess == sess) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
62 rtp_fill_buffer(ssrc, fr, buff);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
63 break;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
64 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
65 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
66
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
67 if ( (force_fps == 0.0) && (fps != NULL) ) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
68 rtp_fill_buffers(rtsp_get_rtp_th(ctl));
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
69 *fps = rtp_get_fps(ssrc);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
70 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
71 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
72 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
73
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
74 demuxer_t* demux_open_rtp(demuxer_t* demuxer)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
75 {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
76 nms_rtsp_hints hints;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
77 char * url = demuxer->stream->streaming_ctrl->url->url;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
78 rtsp_ctrl * ctl;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
79 RTSP_Error reply;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
80 rtsp_medium * media;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
81 Nemesi_DemuxerStreamData * ndsd = calloc(1, sizeof(Nemesi_DemuxerStreamData));
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
82
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
83 memset(&hints,0,sizeof(hints));
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
84 // if (rtsp_port) hints.first_rtp_port = rtsp_port;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
85 if (rtsp_transport_tcp) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
86 hints.pref_rtsp_proto = TCP;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
87 hints.pref_rtp_proto = TCP;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
88 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
89 if (rtsp_transport_sctp) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
90 hints.pref_rtsp_proto = SCTP;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
91 hints.pref_rtp_proto = SCTP;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
92 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
93
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
94 mp_msg(MSGT_DEMUX, MSGL_INFO, "Initializing libNemesi\n");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
95 if ((ctl = rtsp_init(&hints)) == NULL) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
96 free(ndsd);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
97 return STREAM_ERROR;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
98 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
99
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
100 ndsd->rtsp = ctl;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
101 demuxer->priv = ndsd;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
102 //nms_verbosity_set(1);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
103
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
104 mp_msg(MSGT_DEMUX, MSGL_INFO, "Opening: %s\n", url);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
105 if (rtsp_open(ctl, url)) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
106 mp_msg(MSGT_DEMUX, MSGL_ERR, "rtsp_open failed.\n");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
107 return demuxer;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
108 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
109
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
110 reply = rtsp_wait(ctl);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
111 if (reply.got_error) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
112 mp_msg(MSGT_DEMUX, MSGL_ERR,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
113 "OPEN Error from the server: %s\n",
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
114 reply.message.reply_str);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
115 return demuxer;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
116 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
117
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
118 rtsp_play(ctl, 0, 0);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
119 reply = rtsp_wait(ctl);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
120 if (reply.got_error) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
121 mp_msg(MSGT_DEMUX, MSGL_ERR,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
122 "PLAY Error from the server: %s\n",
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
123 reply.message.reply_str);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
124 return demuxer;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
125 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
126
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
127 media = ctl->rtsp_queue->media_queue;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
128 for (; media; media=media->next) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
129 sdp_medium_info * info = media->medium_info;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
130 rtp_session * sess = media->rtp_sess;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
131
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
132 int media_format = atoi(info->fmts);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
133 rtp_pt * ptinfo = rtp_get_pt_info(sess, media_format);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
134 char const * format_name = ptinfo ? ptinfo->name : NULL;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
135
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
136 if (sess->parsers[media_format] == NULL) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
137 mp_msg(MSGT_DEMUX, MSGL_ERR,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
138 "libNemesi unsupported media format: %s\n",
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
139 format_name ? format_name : info->fmts);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
140 continue;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
141 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
142 else {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
143 mp_msg(MSGT_DEMUX, MSGL_INFO,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
144 "libNemesi supported media: %s\n",
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
145 format_name);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
146 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
147
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
148 if (ptinfo->type == AU) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
149 if (ndsd->session[NEMESI_SESSION_AUDIO] == NULL) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
150 sh_audio_t* sh_audio = new_sh_audio(demuxer,0);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
151 WAVEFORMATEX* wf = calloc(1,sizeof(WAVEFORMATEX));
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
152 demux_stream_t* d_audio = demuxer->audio;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
153
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
154 mp_msg(MSGT_DEMUX, MSGL_INFO, "Detected as AUDIO stream...\n");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
155
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
156 link_session_and_fetch_conf(ndsd, NEMESI_SESSION_AUDIO,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
157 sess, NULL, NULL);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
158
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
159 sh_audio->wf = wf;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
160 d_audio->sh = sh_audio;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
161 sh_audio->ds = d_audio;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
162 wf->nSamplesPerSec = 0;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
163
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
164 //List of known audio formats
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
165 if (!strcmp(format_name, "MPA"))
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
166 wf->wFormatTag =
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
167 sh_audio->format = 0x55;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
168 else if (!strcmp(format_name, "vorbis"))
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
169 wf->wFormatTag =
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
170 sh_audio->format = mmioFOURCC('v','r','b','s');
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
171 else
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
172 mp_msg(MSGT_DEMUX, MSGL_WARN,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
173 "Unknown MPlayer format code for MIME"
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
174 " type \"audio/%s\"\n", format_name);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
175 } else {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
176 mp_msg(MSGT_DEMUX, MSGL_ERR,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
177 "There is already an audio session registered,"
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
178 " ignoring...\n");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
179 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
180 } else if (ptinfo->type == VI) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
181 if (ndsd->session[NEMESI_SESSION_AUDIO] == NULL) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
182 sh_video_t* sh_video;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
183 BITMAPINFOHEADER* bih;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
184 demux_stream_t* d_video;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
185 int fps = 0;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
186 rtp_buff buff;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
187
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
188 mp_msg(MSGT_DEMUX, MSGL_INFO, "Detected as VIDEO stream...\n");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
189
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
190 link_session_and_fetch_conf(ndsd, NEMESI_SESSION_VIDEO,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
191 sess, &buff, &fps);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
192
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
193 if (buff.len) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
194 bih = calloc(1,sizeof(BITMAPINFOHEADER)+buff.len);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
195 bih->biSize = sizeof(BITMAPINFOHEADER)+buff.len;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
196 memcpy(bih+1, buff.data, buff.len);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
197 } else {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
198 bih = calloc(1,sizeof(BITMAPINFOHEADER));
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
199 bih->biSize = sizeof(BITMAPINFOHEADER);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
200 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
201
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
202 sh_video = new_sh_video(demuxer,0);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
203 sh_video->bih = bih;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
204 d_video = demuxer->video;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
205 d_video->sh = sh_video;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
206 sh_video->ds = d_video;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
207
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
208 if (fps)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
209 sh_video->fps = fps;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
210
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
211 //List of known video formats
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
212 if (!strcmp(format_name, "MPV")) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
213 bih->biCompression =
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
214 sh_video->format = mmioFOURCC('M','P','E','G');
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
215 } else if (!strcmp(format_name, "H264")) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
216 bih->biCompression =
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
217 sh_video->format = mmioFOURCC('H','2','6','4');
24625
17a83ea47ee1 h263 exposed
lu_zero
parents: 24564
diff changeset
218 } else if (!strcmp(format_name, "H263-1998")) {
17a83ea47ee1 h263 exposed
lu_zero
parents: 24564
diff changeset
219 bih->biCompression =
17a83ea47ee1 h263 exposed
lu_zero
parents: 24564
diff changeset
220 sh_video->format = mmioFOURCC('H','2','6','3');
24564
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
221 } else {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
222 mp_msg(MSGT_DEMUX, MSGL_WARN,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
223 "Unknown MPlayer format code for MIME"
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
224 " type \"video/%s\"\n", format_name);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
225 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
226 } else {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
227 mp_msg(MSGT_DEMUX, MSGL_ERR,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
228 "There is already a video session registered,"
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
229 " ignoring...\n");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
230 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
231 } else {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
232 mp_msg(MSGT_DEMUX, MSGL_ERR, "Unsupported media type\n");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
233 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
234 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
235
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
236 demuxer->stream->eof = 0;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
237
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
238 return demuxer;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
239 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
240
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
241 static int get_data_for_session(Nemesi_DemuxerStreamData * ndsd,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
242 Nemesi_SessionType stype, rtp_frame * fr)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
243 {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
244 rtsp_ctrl * ctl = ndsd->rtsp;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
245 rtp_ssrc *ssrc = NULL;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
246
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
247 for (ssrc = rtp_active_ssrc_queue(rtsp_get_rtp_queue(ctl));
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
248 ssrc;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
249 ssrc = rtp_next_active_ssrc(ssrc)) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
250 if (ssrc->rtp_sess == ndsd->session[stype]) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
251 if (ndsd->first_pkt[stype].len != 0) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
252 fr->data = ndsd->first_pkt[stype].data;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
253 fr->time_sec = ndsd->first_pkt[stype].time_sec;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
254 fr->len = ndsd->first_pkt[stype].len;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
255 ndsd->first_pkt[stype].len = 0;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
256 return RTP_FILL_OK;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
257 } else {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
258 rtp_buff buff;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
259 return rtp_fill_buffer(ssrc, fr, &buff);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
260 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
261 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
262 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
263
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
264 return RTP_SSRC_NOTVALID;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
265 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
266
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
267 int demux_rtp_fill_buffer(demuxer_t* demuxer, demux_stream_t* ds)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
268 {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
269 Nemesi_DemuxerStreamData * ndsd = demuxer->priv;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
270 Nemesi_SessionType stype;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
271 rtsp_ctrl * ctl = ndsd->rtsp;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
272 rtp_thread * rtp_th = rtsp_get_rtp_th(ctl);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
273 rtp_frame fr;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
274
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
275 demux_packet_t* dp;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
276
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
277 if ( (!ctl->rtsp_queue) || (demuxer->stream->eof) || (rtp_fill_buffers(rtp_th)) ) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
278 mp_msg(MSGT_DEMUX, MSGL_INFO, "End of Stream...\n");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
279 demuxer->stream->eof = 1;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
280 return 0;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
281 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
282
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
283 if (ds == demuxer->video)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
284 stype = NEMESI_SESSION_VIDEO;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
285 else if (ds == demuxer->audio)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
286 stype = NEMESI_SESSION_AUDIO;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
287 else
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
288 return 0;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
289
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
290 if(!get_data_for_session(ndsd, stype, &fr)) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
291 dp = new_demux_packet(fr.len);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
292 memcpy(dp->buffer, fr.data, fr.len);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
293 fr.time_sec += ndsd->seek;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
294 ndsd->time[stype] = dp->pts = fr.time_sec;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
295 ds_add_packet(ds, dp);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
296 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
297 else {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
298 stype = (stype + 1) % 2;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
299 if (stype == NEMESI_SESSION_VIDEO)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
300 ds = demuxer->video;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
301 else
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
302 ds = demuxer->audio;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
303
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
304 if(!get_data_for_session(ndsd, stype, &fr)) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
305 dp = new_demux_packet(fr.len);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
306 memcpy(dp->buffer, fr.data, fr.len);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
307 fr.time_sec += ndsd->seek;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
308 ndsd->time[stype] = dp->pts = fr.time_sec;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
309 ds_add_packet(ds, dp);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
310 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
311 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
312
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
313 return 1;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
314 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
315
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
316
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
317 void demux_close_rtp(demuxer_t* demuxer)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
318 {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
319 Nemesi_DemuxerStreamData * ndsd = demuxer->priv;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
320 rtsp_ctrl * ctl = ndsd->rtsp;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
321 RTSP_Error err;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
322
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
323 mp_msg(MSGT_DEMUX, MSGL_INFO, "Closing libNemesi RTSP Stream...\n");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
324
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
325 if (ndsd == NULL)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
326 return;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
327
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
328 free(ndsd);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
329
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
330 if (rtsp_close(ctl)) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
331 err = rtsp_wait(ctl);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
332 if (err.got_error)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
333 mp_msg(MSGT_DEMUX, MSGL_ERR,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
334 "Error Closing Stream: %s\n",
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
335 err.message.reply_str);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
336 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
337
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
338 rtsp_uninit(ctl);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
339 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
340
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
341 static void demux_seek_rtp(demuxer_t *demuxer, float rel_seek_secs,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
342 float audio_delay, int flags)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
343 {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
344 Nemesi_DemuxerStreamData * ndsd = demuxer->priv;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
345 rtsp_ctrl * ctl = ndsd->rtsp;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
346 sdp_attr * r_attr = NULL;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
347 sdp_range r = {0, 0};
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
348 double time = ndsd->time[NEMESI_SESSION_VIDEO] ?
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
349 ndsd->time[NEMESI_SESSION_VIDEO] :
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
350 ndsd->time[NEMESI_SESSION_AUDIO];
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
351
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
352 if (!ctl->rtsp_queue)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
353 return;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
354
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
355 r_attr = sdp_get_attr(ctl->rtsp_queue->info->attr_list, "range");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
356 if (r_attr)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
357 r = sdp_parse_range(r_attr->value);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
358
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
359 //flags & 1 -> absolute seek
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
360 //flags & 2 -> percent seek
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
361 if (flags == 0) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
362 time += rel_seek_secs;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
363 if (time < r.begin)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
364 time = r.begin;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
365 else if (time > r.end)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
366 time = r.end;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
367 ndsd->seek = time;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
368
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
369 mp_msg(MSGT_DEMUX,MSGL_WARN,"libNemesi SEEK %f on %f - %f)\n",
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
370 time, r.begin, r.end);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
371
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
372 if (!rtsp_seek(ctl, time, 0)) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
373 RTSP_Error err = rtsp_wait(ctl);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
374 if (err.got_error) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
375 mp_msg(MSGT_DEMUX, MSGL_ERR,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
376 "Error Performing Seek: %s\n",
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
377 err.message.reply_str);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
378 demuxer->stream->eof = 1;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
379 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
380 else
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
381 mp_msg(MSGT_DEMUX, MSGL_INFO, "Seek, performed\n");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
382 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
383 else {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
384 mp_msg(MSGT_DEMUX, MSGL_ERR, "Unable to pause stream to perform seek\n");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
385 demuxer->stream->eof = 1;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
386 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
387 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
388 else
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
389 mp_msg(MSGT_DEMUX, MSGL_ERR, "Unsupported seek type\n");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
390 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
391
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
392 static int demux_rtp_control(struct demuxer_st *demuxer, int cmd, void *arg)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
393 {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
394 Nemesi_DemuxerStreamData * ndsd = demuxer->priv;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
395 rtsp_ctrl * ctl = ndsd->rtsp;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
396 sdp_attr * r_attr = NULL;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
397 sdp_range r = {0, 0};
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
398 double time = ndsd->time[NEMESI_SESSION_VIDEO] ?
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
399 ndsd->time[NEMESI_SESSION_VIDEO] :
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
400 ndsd->time[NEMESI_SESSION_AUDIO];
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
401
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
402 if (!ctl->rtsp_queue)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
403 return DEMUXER_CTRL_DONTKNOW;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
404
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
405 r_attr = sdp_get_attr(ctl->rtsp_queue->info->attr_list, "range");
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
406 if (r_attr)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
407 r = sdp_parse_range(r_attr->value);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
408
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
409 switch (cmd) {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
410 case DEMUXER_CTRL_GET_TIME_LENGTH:
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
411 if (r.end == 0)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
412 return DEMUXER_CTRL_DONTKNOW;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
413
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
414 *((double *)arg) = ((double)r.end) - ((double)r.begin);
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
415 return DEMUXER_CTRL_OK;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
416
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
417 case DEMUXER_CTRL_GET_PERCENT_POS:
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
418 if (r.end == 0)
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
419 return DEMUXER_CTRL_DONTKNOW;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
420
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
421 *((int *)arg) = (int)( time * 100 / (r.end - r.begin) );
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
422 return DEMUXER_CTRL_OK;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
423 default:
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
424 return DEMUXER_CTRL_DONTKNOW;
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
425 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
426 }
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
427
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
428 demuxer_desc_t demuxer_desc_rtp = {
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
429 "libNemesi demuxer",
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
430 "rtp",
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
431 "",
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
432 "Alessandro Molina",
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
433 "requires libNemesi",
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
434 DEMUXER_TYPE_RTP,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
435 0, // no autodetect
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
436 NULL,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
437 demux_rtp_fill_buffer,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
438 demux_open_rtp,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
439 demux_close_rtp,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
440 demux_seek_rtp,
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
441 demux_rtp_control
e4a38a7cdb81 libnemesi support, yet another rtsp/rtp library...
lu_zero
parents:
diff changeset
442 };