RTP Audio System  2.0.0
advancedaudiodecoder.h
Go to the documentation of this file.
00001 // ##########################################################################
00002 // ####                                                                  ####
00003 // ####                      RTP Audio Server Project                    ####
00004 // ####                    ============================                  ####
00005 // ####                                                                  ####
00006 // #### Advanced Audio Decoder                                           ####
00007 // ####                                                                  ####
00008 // ####           Copyright (C) 1999-2012 by Thomas Dreibholz            ####
00009 // ####                                                                  ####
00010 // #### Contact:                                                         ####
00011 // ####    EMail: dreibh@iem.uni-due.de                                  ####
00012 // ####    WWW:   https://www.nntb.no/~dreibh/rtpaudio                ####
00013 // ####                                                                  ####
00014 // #### ---------------------------------------------------------------- ####
00015 // ####                                                                  ####
00016 // #### This program is free software: you can redistribute it and/or    ####
00017 // #### modify it under the terms of the GNU General Public License as   ####
00018 // #### published by the Free Software Foundation, either version 3 of   ####
00019 // #### the License, or (at your option) any later version.              ####
00020 // ####                                                                  ####
00021 // #### This program is distributed in the hope that it will be useful,  ####
00022 // #### but WITHOUT ANY WARRANTY; without even the implied warranty of   ####
00023 // #### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    ####
00024 // #### GNU General Public License for more details.                     ####
00025 // ####                                                                  ####
00026 // #### You should have received a copy of the GNU General Public        ####
00027 // #### License along with this program.  If not, see                    ####
00028 // #### <http://www.gnu.org/licenses/>.                                  ####
00029 // ####                                                                  ####
00030 // ##########################################################################
00031 // $Id: advancedaudiodecoder.h 1286 2011-12-18 13:43:16Z dreibh $
00032 
00033 
00034 #ifndef ADVANCEDAUDIODECODER_H
00035 #define ADVANCEDAUDIODECODER_H
00036 
00037 
00038 #include "tdsystem.h"
00039 #include "audiowriterinterface.h"
00040 #include "audiodecoderinterface.h"
00041 #include "timedthread.h"
00042 #include "seqnumvalidator.h"
00043 #include "audioquality.h"
00044 #include "advancedaudiopacket.h"
00045 
00046 
00047 #include <set>
00048 #include <map>
00049 
00050 
00060 class AdvancedAudioDecoder : public AudioDecoderInterface,
00061                              public TimedThread
00062 {
00063    // ====== Constructor/Destructor =========================================
00064    public:
00070    AdvancedAudioDecoder(AudioWriterInterface* audioWriter);
00071 
00075    ~AdvancedAudioDecoder();
00076 
00077 
00078    // ====== DecoderInterface implementation ================================
00084    const card16 getTypeID() const;
00085 
00091    const char* getTypeName() const;
00092 
00098    void activate();
00099 
00105    void deactivate();
00106 
00112    void reset();
00113 
00119    void getMediaInfo(MediaInfo& mediaInfo) const;
00120 
00126    card8 getErrorCode() const;
00127 
00133    card64 getPosition() const;
00134 
00140    card64 getMaxPosition() const;
00141 
00147    bool checkNextPacket(DecoderPacket* decoderPacket);
00148 
00154    void handleNextPacket(const DecoderPacket* decoderPacket);
00155 
00156 
00157    // ====== AudioDecoderInterface implementation ===========================
00163    card16 getSamplingRate() const;
00164 
00170    card8 getBits() const;
00171 
00177    card8 getChannels() const;
00178 
00184    card16 getByteOrder() const;
00185 
00186 
00192    cardinal getBytesPerSecond() const;
00193 
00199    cardinal getBitsPerSample() const;
00200 
00201 
00207    AudioQuality getWantedQuality() const;
00208 
00214    void setWantedQuality(const AudioQualityInterface& wantedQuality);
00215 
00216 
00217    // ====== Private data ===================================================
00218    private:
00219    void timerEvent();
00220 
00221    struct FrameFragment {
00222       cardinal Length;
00223       card16   Fragment;
00224       char     Data[0];
00225    };
00226 
00227    struct FrameNode {
00228       card64                                     Position;
00229       card64                                     MaxPosition;
00230       cardinal                                   FrameSize;
00231       card16                                     SamplingRate;
00232       card8                                      Channels;
00233       card8                                      Bits;
00234       card8                                      ErrorCode;
00235       card8                                      pad;
00236       std::multimap<const card16,FrameFragment*> FragmentSetLL;
00237       std::multimap<const card16,FrameFragment*> FragmentSetRL;
00238       std::multimap<const card16,FrameFragment*> FragmentSetLU;
00239       std::multimap<const card16,FrameFragment*> FragmentSetRU;
00240    };
00241 
00242    struct FrameNodeItem {
00243       card64     Position;
00244       FrameNode* Node;
00245 
00246       inline int operator<(const FrameNodeItem& item) const {
00247          return(Position < item.Position);
00248       }
00249    };
00250 
00251    card64 checkFragmentSeqNum(std::multimap<const card16,FrameFragment*>* set,
00252                               const card64                                last) const;
00253    void deleteFragments(std::multimap<const card16,FrameFragment*>* set);
00254    FrameFragment* getFragment(std::multimap<const card16, FrameFragment*>* set,
00255                               const card16                                 fragmentNumber);
00256 
00257 
00258    static const cardinal FrameBufferSize =
00259       2 * ((AdvancedAudioPacket::AdvancedAudioFramesPerSecond /
00260            (16000 / AdvancedAudioPacket::AdvancedAudioMaxTransferDelay)) + 1);
00261 
00262    static const card64 BufferCleanUpDifference =
00263       (4 * FrameBufferSize * PositionStepsPerSecond) /
00264          AdvancedAudioPacket::AdvancedAudioFramesPerSecond;
00265 
00266 
00267    std::multiset<FrameNodeItem> FrameSet;
00268    AudioWriterInterface*        Device;
00269    AudioQuality                 WantedQuality;
00270    card64                       Position;
00271    card64                       MaxPosition;
00272 
00273    SeqNumValidator              SeqNumber[AdvancedAudioPacket::AdvancedAudioMaxQualityLayers];
00274    MediaInfo                    Media;
00275    card16                       AudioSamplingRate;
00276    card8                        AudioBits;
00277    card8                        AudioChannels;
00278    card8                        ErrorCode;
00279 };
00280 
00281 
00282 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines