1 /*
2 * decoder.h --
3 *
4 * FIXME: This file needs a description here.
5 *
6 * Copyright (c) 1993-2002 The Regents of the University of California.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * A. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * B. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * C. Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
22 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef mash_decoder_h
35 #define mash_decoder_h
36
37 #include "tclcl.h"
38 #include "rtp/source.h"
39 #include "audio/controller.h"
40
41 /*FIXME*/
42 #define PLAYO_FILTER 5
43 #define VAR_FILTER 5
44 #define VAR_MULT 2
45
46 class AudioDecoder : public PacketHandler {
47 protected:
48 AudioDecoder();
49 public:
50 virtual ~AudioDecoder();
51
52 /* statistics */
53 void info(char* wrk) const;
54 virtual void stats(char* wrk);
55 virtual int command(int argc, const char*const* argv);
56 protected:
57 void consume_samples(const rtphdr* rh, const u_int8_t* p, int cc);
58 void count(int statno);
59 void setstat(int statno, u_int v);
60 int adapt(const rtphdr*, u_int32_t sclock);
61 int active() const;
62 inline u_int32_t playout() const { return (playout_ >> PLAYO_FILTER); }
63 /*FIXME*/
64 #define MAXSTAT 16
65 struct statcntr {
66 const char* name;
67 u_int cnt;
68 } stat_[MAXSTAT];
69 int nstat_;
70
71 Controller* controller_;
72
73 /*
74 * Playback point estimation state.
75 */
76 int32_t var_; // variance in this host's interarrival time
77 u_int32_t hostoffset_; // timestamp offset this host's clock
78 u_int32_t predicted_drop_; // ts of last drop + blocksize
79 u_int32_t playout_; // playout delay (in media units)
80 u_int32_t lastrecv_; // local time (in media time) of last recv
81 int lecture_mode_; /*FIXME*/
82 int framesize_; /*FIXME*/
83 int block_size_;
84 int maxdel_;
85 };
86
87 class PCM_Decoder : public AudioDecoder {
88 public:
89 virtual void recv(pktbuf*);
90 };
91
92 inline int AudioDecoder::active() const
93 {
94 return (controller_ && controller_->active());
95 }
96
97 /*
98 * Decode steps:
99 * 1. decode (to get blocksize)
100 * 2. adapt (now that we have blocksize)
101 * 3. mix (now that we have adapted)
102 */
103 inline void AudioDecoder::consume_samples(const rtphdr* rh, const u_int8_t* p,
104 int cc)
105 {
106 block_size_ = cc;
107 int plout = adapt(rh, controller_->media_ts());
108 if (plout >= 0)
109 controller_->mix_from_net(plout, p, cc);
110 }
111
112 inline void AudioDecoder::count(int statno)
113 {
114 ++stat_[statno].cnt;
115 }
116
117 inline void AudioDecoder::setstat(int statno, u_int v)
118 {
119 stat_[statno].cnt = v;
120 }
121
122 #endif
123
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.