| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #ifndef AudioPullFIFO_h | 29 #ifndef AudioPullFIFO_h |
| 30 #define AudioPullFIFO_h | 30 #define AudioPullFIFO_h |
| 31 | 31 |
| 32 #include "platform/audio/AudioBus.h" | 32 #include "platform/audio/AudioBus.h" |
| 33 #include "platform/audio/AudioFIFO.h" | 33 #include "platform/audio/AudioFIFO.h" |
| 34 #include "platform/audio/AudioSourceProvider.h" | 34 #include "platform/audio/AudioSourceProvider.h" |
| 35 #include "wtf/Allocator.h" | 35 #include "wtf/Allocator.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 // A FIFO (First In First Out) buffer to handle mismatches in buffer sizes betwe
en a provider and | 39 // A FIFO (First In First Out) buffer to handle mismatches in buffer sizes |
| 40 // receiver. The receiver will "pull" data from this FIFO. If data is already av
ailable in the | 40 // between a provider and receiver. The receiver will "pull" data from this |
| 41 // FIFO, it is provided to the receiver. If insufficient data is available to sa
tisfy the request, | 41 // FIFO. If data is already available in the FIFO, it is provided to the |
| 42 // the FIFO will ask the provider for more data when necessary to fulfill a requ
est. Contrast this | 42 // receiver. If insufficient data is available to satisfy the request, the FIFO |
| 43 // with a "push" FIFO, where the sender pushes data to the FIFO which will itsel
f push the data to | 43 // will ask the provider for more data when necessary to fulfill a request. |
| 44 // the receiver when the FIFO is full. | 44 // Contrast this with a "push" FIFO, where the sender pushes data to the FIFO |
| 45 // which will itself push the data to the receiver when the FIFO is full. |
| 45 class PLATFORM_EXPORT AudioPullFIFO { | 46 class PLATFORM_EXPORT AudioPullFIFO { |
| 46 USING_FAST_MALLOC(AudioPullFIFO); | 47 USING_FAST_MALLOC(AudioPullFIFO); |
| 47 WTF_MAKE_NONCOPYABLE(AudioPullFIFO); | 48 WTF_MAKE_NONCOPYABLE(AudioPullFIFO); |
| 48 | 49 |
| 49 public: | 50 public: |
| 50 // Create a FIFO that gets data from |provider|. The FIFO will be large enough
to hold | 51 // Create a FIFO that gets data from |provider|. The FIFO will be large |
| 51 // |fifoLength| frames of data of |numberOfChannels| channels. The AudioSource
Provider will be | 52 // enough to hold |fifoLength| frames of data of |numberOfChannels| channels. |
| 52 // asked to produce |providerSize| frames when the FIFO needs more data. | 53 // The AudioSourceProvider will be asked to produce |providerSize| frames |
| 54 // when the FIFO needs more data. |
| 53 AudioPullFIFO(AudioSourceProvider& audioProvider, | 55 AudioPullFIFO(AudioSourceProvider& audioProvider, |
| 54 unsigned numberOfChannels, | 56 unsigned numberOfChannels, |
| 55 size_t fifoLength, | 57 size_t fifoLength, |
| 56 size_t providerSize); | 58 size_t providerSize); |
| 57 | 59 |
| 58 // Read |framesToConsume| frames from the FIFO into the destination. If the FI
FO does not have | 60 // Read |framesToConsume| frames from the FIFO into the destination. If the |
| 59 // enough data, we ask the |provider| to get more data to fulfill the request. | 61 // FIFO does not have enough data, we ask the |provider| to get more data to |
| 62 // fulfill the request. |
| 60 void consume(AudioBus* destination, size_t framesToConsume); | 63 void consume(AudioBus* destination, size_t framesToConsume); |
| 61 | 64 |
| 62 private: | 65 private: |
| 63 // Fill the FIFO buffer with at least |numberOfFrames| more data. | 66 // Fill the FIFO buffer with at least |numberOfFrames| more data. |
| 64 void fillBuffer(size_t numberOfFrames); | 67 void fillBuffer(size_t numberOfFrames); |
| 65 | 68 |
| 66 // The provider of the data in our FIFO. | 69 // The provider of the data in our FIFO. |
| 67 AudioSourceProvider& m_provider; | 70 AudioSourceProvider& m_provider; |
| 68 | 71 |
| 69 // The actual FIFO | 72 // The actual FIFO |
| 70 AudioFIFO m_fifo; | 73 AudioFIFO m_fifo; |
| 71 | 74 |
| 72 // Number of frames of data that the provider will produce per call. | 75 // Number of frames of data that the provider will produce per call. |
| 73 unsigned m_providerSize; | 76 unsigned m_providerSize; |
| 74 | 77 |
| 75 // Temporary workspace to hold the data from the provider. | 78 // Temporary workspace to hold the data from the provider. |
| 76 RefPtr<AudioBus> m_tempBus; | 79 RefPtr<AudioBus> m_tempBus; |
| 77 }; | 80 }; |
| 78 | 81 |
| 79 } // namespace blink | 82 } // namespace blink |
| 80 | 83 |
| 81 #endif // AudioPullFIFO.h | 84 #endif // AudioPullFIFO.h |
| OLD | NEW |