aboutsummaryrefslogtreecommitdiff
path: root/modules/pdp_mp4live~.cpp
blob: 2c3f52c9cef9762362b161f183ab3c595ddbbb5c (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
/*
 *   PiDiP module.
 *   Copyright (c) by Yves Degoyon (ydegoyon@free.fr )
 *
 *   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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

/*  This object is a mpeg4ip streaming object towards a Darwin or Quicktime streaming server
 *  A lot of this object code is inspired by the code from mpeg4ip
 *  Copyright (c) 2000, 2001, 2002 Dave Mackie, Bill May & others
 *  The rest is written by Yves Degoyon ( ydegoyon@free.fr )                             
 */


#include "pdp.h"
#include <math.h>
#include <time.h>
#include <sys/time.h>

/* mpeg4ip includes taken from the source tree ( not exported ) */
#include <mp4.h>
#define  DECLARE_CONFIG_VARIABLES
#include "config_set.h"

#undef CONFIG_BOOL
#define CONFIG_BOOL(var, name, defval) \
 { &(var), (name), CONFIG_TYPE_BOOL, (defval), (defval) }
#undef CONFIG_FLOAT
#define CONFIG_FLOAT(var, name, defval) \
 { &(var), (name), CONFIG_TYPE_FLOAT,(float) (defval), (float) (defval) }
#undef CONFIG_INT
#define CONFIG_INT(var, name, defval) \
 { &(var), (name), CONFIG_TYPE_INTEGER,(config_integer_t) (defval), (config_integer_t)(defval) }
#undef CONFIG_STRING
#define CONFIG_STRING(var, name, defval) \
 { &(var), (name), CONFIG_TYPE_STRING, (defval), (defval) }

#include "pdp_mp4config.h"

#undef   DECLARE_CONFIG_VARIABLES
#ifndef debug_message
#define debug_message post 
#endif
#include "rtp_transmitter.h"
#include "pdp_mp4videosource.h"
#include "pdp_mp4audiosource.h"

#define VIDEO_BUFFER_SIZE (1024*1024)
#define MAX_AUDIO_PACKET_SIZE (128 * 1024)
#define AUDIO_PACKET_SIZE (2*1024*2) /* using aac encoding, 2 channels, 2 bytes per sample */

static char   *pdp_mp4live_version = "pdp_mp4live~: version 0.1, an mpeg4ip video streaming object ( ydegoyon@free.fr )";

typedef struct pdp_mp4live_struct
{
    t_object x_obj;
    t_float x_f;

    t_int x_packet0;
    t_int x_dropped;
    t_int x_queue_id;

    t_int x_vwidth;
    t_int x_vheight;
    t_int x_vsize;

    t_outlet *x_outlet_streaming;  // indicates the status of streaming
    t_outlet *x_outlet_nbframes;   // number of frames emitted
    t_outlet *x_outlet_framerate;  // current frame rate

    t_int x_streaming;   // streaming flag
    t_int x_nbframes;    // number of frames emitted
    t_int x_framerate;   // framerate

    t_int x_cursec;   // current second
    t_int x_secondcount; // number of frames emitted in the current second

      /* audio structures */
    short x_audio_buf[2*MAX_AUDIO_PACKET_SIZE]; /* buffer for incoming audio */
    t_int x_audioin_position; // writing position for incoming audio
    t_int x_audio_per_frame;  // number of audio samples to transmit for each frame

      /* mpeg4ip data */
    CLiveConfig *x_mp4Config;
    CRtpTransmitter *x_rtpTransmitter;
    CPDPVideoSource *x_videosource;
    CPDPAudioSource *x_audiosource;

} t_pdp_mp4live;

#ifdef __cplusplus
extern "C"
{
#endif

static void pdp_mp4live_add_sink(t_pdp_mp4live *x, CMediaSink* pSink)
{
   if (x->x_videosource)
   {
      x->x_videosource->AddSink(pSink);
   }
   if (x->x_audiosource)
   {
      x->x_audiosource->AddSink(pSink);
   }
}

static void pdp_mp4live_remove_sink(t_pdp_mp4live *x, CMediaSink* pSink)
{
   if (x->x_videosource)
   {
      x->x_videosource->RemoveSink(pSink);
   }
   if (x->x_audiosource)
   {
      x->x_audiosource->RemoveSink(pSink);
   }
}

static void pdp_mp4live_disconnect(t_pdp_mp4live *x)
{
 t_int ret, i;

   if (!x->x_streaming)
   {
     post("pdp_mp4live~ : disconnect request but not connected ... ignored" );
     return;
   }

   if (x->x_audiosource) 
   {
     x->x_audiosource->DoStop();
     delete x->x_audiosource;
     x->x_audiosource = NULL;
   }

   if (x->x_videosource) 
   {
     x->x_videosource->DoStop();
     delete x->x_videosource;
     x->x_videosource = NULL;
   }

   if (x->x_rtpTransmitter) 
   {
     pdp_mp4live_remove_sink(x, x->x_rtpTransmitter);
     x->x_rtpTransmitter->StopThread();
     delete x->x_rtpTransmitter;
     x->x_rtpTransmitter = NULL;
   }

   x->x_streaming = 0;
   outlet_float( x->x_outlet_streaming, x->x_streaming );
   x->x_nbframes = 0;
   outlet_float( x->x_outlet_nbframes, x->x_nbframes );
   x->x_framerate = 0;
   outlet_float( x->x_outlet_framerate, x->x_framerate );
}

static void pdp_mp4live_connect(t_pdp_mp4live *x )
{
  t_int ret, i;

   if (x->x_streaming)
   {
     post("pdp_mp4live~ : connect request but already connected ... ignored" );
     return;
   }

   post("pdp_mp4live~ : creating video source");
   if ( x->x_videosource == NULL )
   {
      x->x_videosource = new CPDPVideoSource();
      x->x_videosource->SetConfig(x->x_mp4Config);
   }
   
   post("pdp_mp4live~ : creating audio source");
   if ( x->x_audiosource == NULL )
   {
       x->x_audiosource = new CPDPAudioSource(x->x_mp4Config);
   }

   post("pdp_mp4live~ : creating rtp transmitter");
   x->x_rtpTransmitter = new CRtpTransmitter(x->x_mp4Config);
   x->x_rtpTransmitter->StartThread();

   post("pdp_mp4live~ : creating audio destination");
   x->x_rtpTransmitter->CreateAudioRtpDestination(0,
                      x->x_mp4Config->GetStringValue(CONFIG_RTP_AUDIO_DEST_ADDRESS),
                      x->x_mp4Config->GetIntegerValue(CONFIG_RTP_AUDIO_DEST_PORT),
                      0);

   post("pdp_mp4live~ : creating video destination");
   x->x_rtpTransmitter->CreateVideoRtpDestination(0,
                     x->x_mp4Config->GetStringValue(CONFIG_RTP_DEST_ADDRESS),
                     x->x_mp4Config->GetIntegerValue(CONFIG_RTP_VIDEO_DEST_PORT),
                     0);

   post("pdp_mp4live~ : starting rtp");
   if ( x->x_rtpTransmitter )
   {
      pdp_mp4live_add_sink(x, x->x_rtpTransmitter);
      x->x_rtpTransmitter->Start();
   }

   if (x->x_videosource) 
   {
      post("pdp_mp4live~ : starting video source");
      x->x_videosource->DoStart();
      post("pdp_mp4live~ : generating key frame");
      x->x_videosource->GenerateKeyFrame();
   }

   if (x->x_audiosource) 
   {
      post("pdp_mp4live~ : starting audio source");
      x->x_audiosource->DoStart();
   }

   x->x_streaming = 1;
   outlet_float( x->x_outlet_streaming, x->x_streaming );
   x->x_nbframes = 0;
   outlet_float( x->x_outlet_nbframes, x->x_nbframes );
   x->x_framerate = 0;
   outlet_float( x->x_outlet_framerate, x->x_framerate );

}

static void pdp_mp4live_ipaddr(t_pdp_mp4live *x, t_symbol *sIpAddr )
{
  t_int a, b, c, d;

   if ( !strcmp( sIpAddr->s_name, "" ) )
   {
     post("pdp_mp4live~ : wrong ip address" );
     return;
   }

   if ( sscanf( sIpAddr->s_name, "%d.%d.%d.%d", &a, &b, &c, &d ) < 4 )
   {
     post("pdp_mp4live~ : wrong ip address : %s", sIpAddr->s_name );
     return;
   }

   post( "pdp_mp4live~ : setting ip address: %s", sIpAddr->s_name );
   x->x_mp4Config->SetStringValue( CONFIG_RTP_DEST_ADDRESS, sIpAddr->s_name );
   x->x_mp4Config->SetStringValue( CONFIG_RTP_AUDIO_DEST_ADDRESS, sIpAddr->s_name );
}

static void pdp_mp4live_aport(t_pdp_mp4live *x, t_floatarg fAudioPort )
{
   if ( ( (t_int) fAudioPort <= 0 ) || ( (t_int) fAudioPort > 65535 ) )
   {
     post("pdp_mp4live~ : wrong audio port : %d", fAudioPort );
     return;
   }

   post( "pdp_mp4live~ : setting audio port: %d", (t_int) fAudioPort );
   x->x_mp4Config->SetIntegerValue( CONFIG_RTP_AUDIO_DEST_PORT, (t_int) fAudioPort );

}

static void pdp_mp4live_vport(t_pdp_mp4live *x, t_floatarg fVideoPort )
{
   if ( ( (t_int) fVideoPort <= 0 ) || ( (t_int) fVideoPort > 65535 ) )
   {
     post("pdp_mp4live~ : wrong video port : %d", fVideoPort );
     return;
   }

   post( "pdp_mp4live~ : setting video port: %d", (t_int) fVideoPort );
   x->x_mp4Config->SetIntegerValue( CONFIG_RTP_VIDEO_DEST_PORT, (t_int) fVideoPort );

}

static void pdp_mp4live_ttl(t_pdp_mp4live *x, t_floatarg fTtl )
{
   if ( ( (t_int) fTtl <= 0 ) || ( (t_int) fTtl > 255 ) )
   {
     post("pdp_mp4live~ : wrong ttl : %d", fTtl );
     return;
   }

   post( "pdp_mp4live~ : setting ttl : %d", (t_int) fTtl );
   x->x_mp4Config->SetIntegerValue( CONFIG_RTP_MCAST_TTL, (t_int) fTtl );

}

static void pdp_mp4live_vwidth(t_pdp_mp4live *x, t_floatarg fWidth )
{
   if ( ( (t_int) fWidth <= 0 ) )
   {
     post("pdp_mp4live~ : wrong width : %d", fWidth );
     return;
   }

   post( "pdp_mp4live~ : setting width : %d", (t_int) fWidth );
   x->x_mp4Config->SetIntegerValue( CONFIG_VIDEO_RAW_WIDTH, (t_int) fWidth );

}

static void pdp_mp4live_vheight(t_pdp_mp4live *x, t_floatarg fHeight )
{
   if ( ( (t_int) fHeight <= 0 ) )
   {
     post("pdp_mp4live~ : wrong height : %d", fHeight );
     return;
   }

   post( "pdp_mp4live~ : setting height : %d", (t_int) fHeight );
   x->x_mp4Config->SetIntegerValue( CONFIG_VIDEO_RAW_HEIGHT, (t_int) fHeight );

}

static void pdp_mp4live_framerate(t_pdp_mp4live *x, t_floatarg fFrameRate )
{
   if ( ( (t_int) fFrameRate <= 0 ) )
   {
     post("pdp_mp4live~ : wrong framerate : %d", fFrameRate );
     return;
   }

   post( "pdp_mp4live~ : setting framerate : %d", (t_int) fFrameRate );
   x->x_mp4Config->SetFloatValue( CONFIG_VIDEO_FRAME_RATE, (t_float) fFrameRate );

}

static void pdp_mp4live_vbitrate(t_pdp_mp4live *x, t_floatarg fVBitrate )
{
   if ( ( (t_int) fVBitrate <= 0 ) )
   {
     post("pdp_mp4live~ : wrong video bit rate : %d", fVBitrate );
     return;
   }

   post( "pdp_mp4live~ : setting video bit rate : %d", (t_int) fVBitrate );
   x->x_mp4Config->SetIntegerValue( CONFIG_VIDEO_BIT_RATE, (t_int) fVBitrate );

}

static void pdp_mp4live_samplerate(t_pdp_mp4live *x, t_floatarg fSampleRate )
{
   if ( ( (t_int) fSampleRate != 44100 ) &&
        ( (t_int) fSampleRate != 22050 ) &&
        ( (t_int) fSampleRate != 11025 ) &&
        ( (t_int) fSampleRate != 8000 )
        )
   {
     post("pdp_mp4live~ : wrong samplerate : %d", fSampleRate );
     return;
   }

   post( "pdp_mp4live~ : setting samplerate : %d", (t_int) fSampleRate );
   x->x_mp4Config->SetIntegerValue( CONFIG_AUDIO_SAMPLE_RATE, (t_int) fSampleRate );

}

static void pdp_mp4live_abitrate(t_pdp_mp4live *x, t_floatarg fABitrate )
{
   if ( ( (t_int) fABitrate <= 0 ) )
   {
     post("pdp_mp4live~ : wrong audio bit rate : %d", fABitrate );
     return;
   }

   post( "pdp_mp4live~ : setting audio bit rate : %d", (t_int) fABitrate );
   x->x_mp4Config->SetIntegerValue( CONFIG_AUDIO_BIT_RATE_KBPS, (t_int) fABitrate );
   x->x_mp4Config->SetIntegerValue( CONFIG_AUDIO_BIT_RATE, ((t_int) fABitrate)*1000 );

}

static void pdp_mp4live_sdp(t_pdp_mp4live *x, t_symbol *sSdpFile )
{
  t_int ret;

   post( "pdp_mp4live~ : setting sdp filename : %s", (char *) sSdpFile->s_name );
   x->x_mp4Config->SetStringValue( CONFIG_SDP_FILE_NAME, (char *) sSdpFile->s_name );

   post( "pdp_mp4live~ : writing sdp file : %s", (char *) sSdpFile->s_name );
   if ( ( ret = GenerateSdpFile( x->x_mp4Config ) ) )
   {
     post( "pdp_mp4live~ : written sdp file : %s", (char *) sSdpFile->s_name );
   }
   else
   {
     post( "pdp_mp4live~ : could not write sdp file : %s", 
            (char *) sSdpFile->s_name );
   }
}

static void pdp_mp4live_process_yv12(t_pdp_mp4live *x)
{
    t_pdp     *header = pdp_packet_header(x->x_packet0);
    u_int8_t  *data   = (uint8_t *)pdp_packet_data(x->x_packet0);
    u_int8_t  *pY, *pU, *pV;
    struct timeval etime;

        /* allocate all ressources */
    if ( ((int)header->info.image.width != x->x_vwidth) ||
         ((int)header->info.image.height != x->x_vheight) )
    {
        x->x_vwidth = header->info.image.width;
        x->x_vheight = header->info.image.height;
        x->x_vsize = x->x_vwidth*x->x_vheight;
    }

    if ( x->x_streaming )
    {
         pY = data;
         pU = data+x->x_vsize;
         pV = data+x->x_vsize+(x->x_vsize>>2);

            /* update frames counter */

         if ( gettimeofday(&etime, NULL) == -1)
         {
            post("pdp_ffmpeg~ : could not read time" );
         }
         if ( etime.tv_sec != x->x_cursec )
         {
            x->x_cursec = etime.tv_sec;
            x->x_framerate = x->x_secondcount;
            x->x_secondcount = 0;
         }
         x->x_nbframes++;
         x->x_secondcount++;

         x->x_videosource->ProcessVideo( pY, pV, pU );

    }
    return;
}

static void pdp_mp4live_killpacket(t_pdp_mp4live *x)
{
    /* delete source packet */
    pdp_packet_mark_unused(x->x_packet0);
    x->x_packet0 = -1;
}

    /* store audio data in PCM format and stream it */
static t_int *pdp_mp4live_perform(t_int *w)
{
  t_float *in1   = (t_float *)(w[1]);       // left audio inlet
  t_float *in2   = (t_float *)(w[2]);       // right audio inlet 
  t_pdp_mp4live *x = (t_pdp_mp4live *)(w[3]);
  int n = (int)(w[4]);                      // number of samples 
  t_float fsample;
  t_int   isample, i;

    // just fills the buffer ( a pcm buffer )
    while (n--)
    {
       fsample=*(in1++); 
       if (fsample > 1.0) { fsample = 1.0; }
       if (fsample < -1.0) { fsample = -1.0; }
       isample=(short) (32767.0 * fsample);
       *(x->x_audio_buf+x->x_audioin_position)=isample;
       x->x_audioin_position=(x->x_audioin_position+1)%(2*MAX_AUDIO_PACKET_SIZE); 
       if ( x->x_audioin_position == 2*MAX_AUDIO_PACKET_SIZE-1 ) 
       {
          // post( "pdp_mp4live~ : reaching end of audio buffer" );
       }
       fsample=*(in2++); 
       if (fsample > 1.0) { fsample = 1.0; }
       if (fsample < -1.0) { fsample = -1.0; }
       isample=(short) (32767.0 * fsample);
       *(x->x_audio_buf+x->x_audioin_position)=isample;
       x->x_audioin_position=(x->x_audioin_position+1)%(2*MAX_AUDIO_PACKET_SIZE); 
       if ( x->x_audioin_position == 2*MAX_AUDIO_PACKET_SIZE-1 ) 
       {
          // post( "pdp_mp4live~ : reaching end of audio buffer" );
       }
    }

    if ( x->x_streaming )
    {
          /* send an audio frame */
       if ( (t_int)(x->x_audioin_position*sizeof(short)) > (t_int)x->x_audio_per_frame )
       {
         x->x_audiosource->ProcessAudio( (u_int8_t*)x->x_audio_buf, 
                        (u_int32_t)x->x_audio_per_frame );

           /* recopy the buffer and set new pointers */
         memcpy( x->x_audio_buf, x->x_audio_buf+(x->x_audio_per_frame/sizeof(short)), 
                    x->x_audioin_position*sizeof(short)-x->x_audio_per_frame ); 
         x->x_audioin_position-=(x->x_audio_per_frame/sizeof(short));
       }
    }
 
    return (w+5);
}

static void pdp_mp4live_dsp(t_pdp_mp4live *x, t_signal **sp)
{
    dsp_add(pdp_mp4live_perform, 4, sp[0]->s_vec, sp[1]->s_vec, x, sp[0]->s_n);
}

static void pdp_mp4live_process(t_pdp_mp4live *x)
{
   int encoding;
   t_pdp *header = 0;

   /* check if image data packets are compatible */
   if ( (header = pdp_packet_header(x->x_packet0))
	&& (PDP_BITMAP == header->type)){
    
	/* pdp_mp4live_process inputs and write into active inlet */
	switch(pdp_packet_header(x->x_packet0)->info.image.encoding)
        {

	  case PDP_BITMAP_YV12:
            pdp_queue_add(x, (void*) pdp_mp4live_process_yv12, (void*) pdp_mp4live_killpacket, &x->x_queue_id);
            outlet_float( x->x_outlet_nbframes, x->x_nbframes );
            outlet_float( x->x_outlet_framerate, x->x_framerate );
	    break;

	  default:
	    /* don't know the type, so dont pdp_mp4live_process */
            post( "pdp_mp4live~ : hey!! i don't know about that type of image : %d", 
                  pdp_packet_header(x->x_packet0)->info.image.encoding );
	    break;
	    
	}
    }

}

static void pdp_mp4live_input_0(t_pdp_mp4live *x, t_symbol *s, t_floatarg f)
{

    /* if this is a register_ro message or register_rw message, register with packet factory */

    if (s== gensym("register_rw"))
    {
       x->x_dropped = pdp_packet_convert_ro_or_drop(&x->x_packet0, (int)f, pdp_gensym("bitmap/yv12/*") );
    }

    if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped))
    {
        /* add the process method and callback to the process queue */
        pdp_mp4live_process(x);
    }

}

static void pdp_mp4live_free(t_pdp_mp4live *x)
{
  int i;

    pdp_queue_finish(x->x_queue_id);
    pdp_packet_mark_unused(x->x_packet0);
}

t_class *pdp_mp4live_class;

void *pdp_mp4live_new(void)
{
    int i;

    t_pdp_mp4live *x = (t_pdp_mp4live *)pd_new(pdp_mp4live_class);
    inlet_new (&x->x_obj, &x->x_obj.ob_pd, gensym ("signal"), gensym ("signal"));

    x->x_outlet_streaming = outlet_new(&x->x_obj, &s_float);
    x->x_outlet_nbframes = outlet_new(&x->x_obj, &s_float);
    x->x_outlet_framerate = outlet_new(&x->x_obj, &s_float);

    x->x_packet0 = -1;
    x->x_queue_id = -1;
    x->x_nbframes = 0;
    x->x_framerate = 0;
    x->x_secondcount = 0;
    x->x_audioin_position = 0;

    x->x_mp4Config = new CLiveConfig(PdpConfigVariables,
                     sizeof(PdpConfigVariables) / sizeof(SConfigVariable),
                     "none");
    if ( x->x_mp4Config == NULL )
    {
       post( "pdp_mp4live~ : couldn't allocate default config" );
       return NULL;
    }

    x->x_mp4Config->InitializeIndexes();

    x->x_mp4Config->Update();

    // update sample rate with the actual sample rate
    x->x_mp4Config->SetIntegerValue( CONFIG_AUDIO_SAMPLE_RATE, (t_int) sys_getsr() );

    x->x_videosource = NULL;
    x->x_audiosource = NULL;

    x->x_audio_per_frame = AUDIO_PACKET_SIZE;

    return (void *)x;
}


void pdp_mp4live_tilde_setup(void)
{
    // post( pdp_mp4live_version );
    pdp_mp4live_class = class_new(gensym("pdp_mp4live~"), (t_newmethod)pdp_mp4live_new,
    	(t_method)pdp_mp4live_free, sizeof(t_pdp_mp4live), 0, A_NULL);

    CLASS_MAINSIGNALIN(pdp_mp4live_class, t_pdp_mp4live, x_f );
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_dsp, gensym("dsp"), A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_connect, gensym("connect"), A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_ipaddr, gensym("ipaddr"), A_SYMBOL, A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_aport, gensym("audioport"), A_DEFFLOAT, A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_vport, gensym("videoport"), A_DEFFLOAT, A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_ttl, gensym("ttl"), A_DEFFLOAT, A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_vwidth, gensym("vwidth"), A_DEFFLOAT, A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_vheight, gensym("vheight"), A_DEFFLOAT, A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_framerate, gensym("framerate"), A_DEFFLOAT, A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_vbitrate, gensym("vbitrate"), A_DEFFLOAT, A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_samplerate, gensym("samplerate"), A_DEFFLOAT, A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_abitrate, gensym("abitrate"), A_DEFFLOAT, A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_disconnect, gensym("disconnect"), A_NULL);
    class_addmethod(pdp_mp4live_class, (t_method)pdp_mp4live_sdp, gensym("sdp"), A_SYMBOL, A_NULL);
    class_sethelpsymbol( pdp_mp4live_class, gensym("pdp_mp4live~.pd") );
}

#ifdef __cplusplus
}
#endif