~ubuntu-branches/ubuntu/trusty/mpeg4ip/trusty

« back to all changes in this revision

Viewing changes to player/src/audio_buffer.h

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2008-01-12 15:59:56 UTC
  • Revision ID: james.westby@ubuntu.com-20080112155956-1vznw5njidvrh649
Tags: upstream-1.6dfsg
ImportĀ upstreamĀ versionĀ 1.6dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The contents of this file are subject to the Mozilla Public
 
3
 * License Version 1.1 (the "License"); you may not use this file
 
4
 * except in compliance with the License. You may obtain a copy of
 
5
 * the License at http://www.mozilla.org/MPL/
 
6
 * 
 
7
 * Software distributed under the License is distributed on an "AS
 
8
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
9
 * implied. See the License for the specific language governing
 
10
 * rights and limitations under the License.
 
11
 * 
 
12
 * The Original Code is MPEG4IP.
 
13
 * 
 
14
 * The Initial Developer of the Original Code is Cisco Systems Inc.
 
15
 * Portions created by Cisco Systems Inc. are
 
16
 * Copyright (C) Cisco Systems Inc. 2004.  All Rights Reserved.
 
17
 * 
 
18
 * Contributor(s): 
 
19
 *              Bill May        wmay@cisco.com
 
20
 */
 
21
 
 
22
#ifndef __AUDIO_BUFFER_H__
 
23
#define __AUDIO_BUFFER_H__ 1
 
24
 
 
25
#include "audio.h"
 
26
 
 
27
class CBufferAudioSync : public CAudioSync {
 
28
 public:
 
29
  CBufferAudioSync(CPlayerSession *psptr, int volume);
 
30
  ~CBufferAudioSync(void);
 
31
 
 
32
  // APIs from plugins
 
33
  uint8_t *get_audio_buffer(uint32_t freq_ts, uint64_t ts);
 
34
  void filled_audio_buffer(void);
 
35
  void set_config(uint32_t freq, uint32_t chans, 
 
36
                      audio_format_t format, uint32_t samples_per_frame);
 
37
  void load_audio_buffer(const uint8_t *from,
 
38
                         uint32_t bytes, 
 
39
                         uint32_t freq_ts,
 
40
                         uint64_t ts);
 
41
  // APIs from decoder task
 
42
  void flush_decode_buffers(void);
 
43
 
 
44
  // APIs from sync task
 
45
  int initialize_audio(int have_video);
 
46
  int is_audio_ready(uint64_t &disptime);
 
47
  bool check_audio_sync(uint64_t current_time, 
 
48
                        uint64_t &resync_time,
 
49
                        int64_t &wait_time,
 
50
                        bool &have_eof, 
 
51
                        bool &restart_sync);
 
52
  void flush_sync_buffers(void);
 
53
  void play_audio(void);
 
54
  virtual void set_volume(int volume) = 0;
 
55
  void display_status(void);
 
56
 protected:
 
57
  // APIs for hardware routines
 
58
  // initialize hardware needs to call audio_convert_init.
 
59
  bool audio_buffer_callback(uint8_t *outbuf, 
 
60
                             uint32_t len_bytes,
 
61
                             uint32_t latency_samples,
 
62
                             uint64_t current_time);
 
63
  virtual int InitializeHardware(void) = 0;
 
64
  virtual void StartHardware(void)  = 0;
 
65
  virtual void StopHardware(void) = 0;
 
66
  virtual void CopyBytesToHardware(uint8_t *from, 
 
67
                                   uint8_t *to, 
 
68
                                   uint32_t bytes) = 0;
 
69
  virtual bool Lock(void) {
 
70
    SDL_LockMutex(m_mutex);
 
71
    return true;
 
72
  };
 
73
  virtual void Unlock(void) {
 
74
    SDL_UnlockMutex(m_mutex);
 
75
  };
 
76
 protected:
 
77
  SDL_mutex *m_mutex;
 
78
  bool m_audio_configured;
 
79
  uint32_t m_freq;
 
80
  
 
81
  uint8_t *m_sample_buffer;
 
82
  uint32_t m_sample_buffer_size;
 
83
  uint32_t m_fill_offset;
 
84
  uint32_t m_play_offset;
 
85
  uint32_t m_filled_bytes;
 
86
 
 
87
  uint32_t m_output_buffer_size_bytes; // filled in by InitializeHardware
 
88
 
 
89
  uint32_t m_bytes_per_frame;
 
90
  uint32_t m_samples_per_frame;
 
91
  uint32_t m_msec_per_frame;
 
92
 
 
93
  uint8_t *m_local_buffer;
 
94
  uint64_t m_first_ts;
 
95
  uint32_t m_first_freq_ts;
 
96
  bool m_first_filled;
 
97
  uint64_t m_buffer_next_ts;      // next ts to fill
 
98
  uint32_t m_buffer_next_freq_ts; // same here
 
99
  
 
100
  uint64_t m_got_buffer_ts;
 
101
  uint32_t m_got_buffer_freq_ts;
 
102
  uint32_t m_got_buffer_silence_bytes;
 
103
  volatile bool m_dont_fill;
 
104
  volatile bool m_audio_waiting_buffer;
 
105
  SDL_sem *m_audio_waiting;
 
106
 
 
107
  bool     m_have_resync;
 
108
  bool     m_waiting_on_resync;
 
109
  uint32_t m_resync_offset;
 
110
  uint32_t m_resync_freq_ts;
 
111
  uint64_t m_resync_ts;
 
112
 
 
113
  bool     m_restart_request;
 
114
  uint8_t m_silence;
 
115
 
 
116
  bool m_hardware_initialized;
 
117
  int m_volume;
 
118
 
 
119
  bool m_first_callback;
 
120
  uint64_t m_hw_start_time;
 
121
  uint64_t m_samples_written;
 
122
  uint64_t m_latency_value;
 
123
 
 
124
  uint64_t m_total_samples_played;
 
125
  uint64_t m_sync_samples_added;
 
126
  uint64_t m_sync_samples_removed;
 
127
  bool m_have_jitter;
 
128
  int64_t m_jitter_msec_total;
 
129
  int64_t m_jitter_msec;
 
130
  uint64_t m_jitter_calc_ts;
 
131
  uint32_t m_jitter_calc_freq_ts;
 
132
  bool m_audio_paused;
 
133
  bool m_last_add_samples;
 
134
  uint64_t m_last_diff;
 
135
  // helper routines for buffer fill routines
 
136
  bool do_we_need_resync(uint32_t freq_ts, uint32_t &silence_samples);
 
137
  void wait_for_callback(void);
 
138
  void fill_silence(uint32_t silence_bytes);
 
139
  bool check_for_bytes(uint32_t bytes, uint32_t silence_bytes);
 
140
 
 
141
  void callback_done(void);
 
142
};
 
143
  
 
144
  
 
145
#endif