Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(981)

Side by Side Diff: media/audio/audio_device_thread.h

Issue 1487983002: Forward the number of skipped frames by the OS in audio playout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ 5 #ifndef MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
6 #define MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ 6 #define MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 int total_segments); 43 int total_segments);
44 virtual ~Callback(); 44 virtual ~Callback();
45 45
46 // One time initialization for the callback object on the audio thread. 46 // One time initialization for the callback object on the audio thread.
47 void InitializeOnAudioThread(); 47 void InitializeOnAudioThread();
48 48
49 // Derived implementations must call shared_memory_.Map appropriately 49 // Derived implementations must call shared_memory_.Map appropriately
50 // before Process can be called. 50 // before Process can be called.
51 virtual void MapSharedMemory() = 0; 51 virtual void MapSharedMemory() = 0;
52 52
53 // Called whenever we receive notifications about pending data. 53 // Called whenever we receive notifications about pending input data.
54 virtual void Process(uint32 pending_data) = 0; 54 virtual void Process(uint32_t pending_data) = 0;
55
56 // Called before ProcessInput() if the consumer has skipped any frames. The
57 // source can handle this appropriately depending on its type. An ordinary
58 // file playout would ignore this. Only used for output.
59 virtual void FramesSkipped(uint32_t frames_skipped) = 0;
55 60
56 protected: 61 protected:
57 // Protected so that derived classes can access directly. 62 // Protected so that derived classes can access directly.
58 // The variables are 'const' since values are calculated/set in the 63 // The variables are 'const' since values are calculated/set in the
59 // constructor and must never change. 64 // constructor and must never change.
60 const AudioParameters audio_parameters_; 65 const AudioParameters audio_parameters_;
61 const int samples_per_ms_; 66 const int samples_per_ms_;
62 const int bytes_per_ms_; 67 const int bytes_per_ms_;
63 68
64 base::SharedMemory shared_memory_; 69 base::SharedMemory shared_memory_;
65 const int memory_length_; 70 const int memory_length_;
66 const int total_segments_; 71 const int total_segments_;
67 int segment_length_; 72 int segment_length_;
68 73
69 private: 74 private:
70 DISALLOW_COPY_AND_ASSIGN(Callback); 75 DISALLOW_COPY_AND_ASSIGN(Callback);
71 }; 76 };
72 77
73 AudioDeviceThread(); 78 AudioDeviceThread();
74 ~AudioDeviceThread(); 79 ~AudioDeviceThread();
75 80
76 // Starts the audio thread. The thread must not already be running. If 81 // Starts the audio thread. The thread must not already be running. If
77 // |sychronized_buffers| is set, the browser expects to be notified via the 82 // |sychronized_buffers| is set, the browser expects to be notified via the
78 // |socket| every time AudioDeviceThread::Process() completes. 83 // |socket| every time AudioDeviceThread::Process() completes. |input| should
84 // be true for input and false for output. It is used for reading the right
85 // amount of data from the socket.
86 // TODO(grunell): |input| is ugly, but there is plans to re-use a thread for
tommi (sloooow) - chröme 2015/12/01 13:34:25 s/is plans/are plans
Henrik Grunell 2015/12/03 17:01:06 Done.
87 // multiple inputs/outputs (see todo comment above) so we do it this way
88 // meanwhile instead of using separating classes.
tommi (sloooow) - chröme 2015/12/01 13:34:25 using separate classes
Henrik Grunell 2015/12/03 17:01:06 Done.
79 void Start(AudioDeviceThread::Callback* callback, 89 void Start(AudioDeviceThread::Callback* callback,
80 base::SyncSocket::Handle socket, 90 base::SyncSocket::Handle socket,
81 const char* thread_name, 91 const char* thread_name,
82 bool synchronized_buffers); 92 bool synchronized_buffers,
93 bool input);
83 94
84 // This tells the audio thread to stop and clean up the data. 95 // This tells the audio thread to stop and clean up the data.
85 // The method can stop the thread synchronously or asynchronously. 96 // The method can stop the thread synchronously or asynchronously.
86 // In the latter case, the thread will still be running after Stop() 97 // In the latter case, the thread will still be running after Stop()
87 // returns, but the callback pointer is cleared so no further callbacks will 98 // returns, but the callback pointer is cleared so no further callbacks will
88 // be made (IOW after Stop() returns, it is safe to delete the callback). 99 // be made (IOW after Stop() returns, it is safe to delete the callback).
89 // The |loop_for_join| parameter is required for asynchronous operation 100 // The |loop_for_join| parameter is required for asynchronous operation
90 // in order to join the worker thread and close the thread handle later via a 101 // in order to join the worker thread and close the thread handle later via a
91 // posted task. 102 // posted task.
92 // If set to NULL, function will wait for the thread to exit before returning. 103 // If set to NULL, function will wait for the thread to exit before returning.
(...skipping 14 matching lines...) Expand all
107 118
108 base::Lock thread_lock_; 119 base::Lock thread_lock_;
109 scoped_refptr<AudioDeviceThread::Thread> thread_; 120 scoped_refptr<AudioDeviceThread::Thread> thread_;
110 121
111 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread); 122 DISALLOW_COPY_AND_ASSIGN(AudioDeviceThread);
112 }; 123 };
113 124
114 } // namespace media. 125 } // namespace media.
115 126
116 #endif // MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_ 127 #endif // MEDIA_AUDIO_AUDIO_DEVICE_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698