| 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 consumer. The consumer 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 // consumer. If available data is insufficient 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 until it is enough to fulfill a request. |
| 44 // the receiver when the FIFO is full. | 44 // |
| 45 // Provider (e.g destination node) |
| 46 // | (pull) |
| 47 // v |
| 48 // AudioPullFIFO |
| 49 // | (consume) |
| 50 // v |
| 51 // Consumer (e.g. AudioRenderSink) |
| 52 // |
| 45 class PLATFORM_EXPORT AudioPullFIFO { | 53 class PLATFORM_EXPORT AudioPullFIFO { |
| 46 USING_FAST_MALLOC(AudioPullFIFO); | 54 USING_FAST_MALLOC(AudioPullFIFO); |
| 47 WTF_MAKE_NONCOPYABLE(AudioPullFIFO); | 55 WTF_MAKE_NONCOPYABLE(AudioPullFIFO); |
| 56 |
| 48 public: | 57 public: |
| 49 // Create a FIFO that gets data from |provider|. The FIFO will be large enou
gh to hold | 58 // Create a FIFO that gets data from |provider|. The FIFO will be large |
| 50 // |fifoLength| frames of data of |numberOfChannels| channels. The AudioSour
ceProvider will be | 59 // enough to hold |fifoBufferLength| frames of data of |numberOfChannels| |
| 51 // asked to produce |providerSize| frames when the FIFO needs more data. | 60 // channels. The AudioSourceProvider will be asked to produce |
| 52 AudioPullFIFO(AudioSourceProvider& audioProvider, unsigned numberOfChannels,
size_t fifoLength, size_t providerSize); | 61 // |providerRenderBlockSize| frames when the FIFO needs more data. |
| 62 AudioPullFIFO(unsigned numberOfChannels, size_t fifoBufferLength, AudioSourc
eProvider&, size_t providerRenderBlockSize); |
| 53 | 63 |
| 54 // Read |framesToConsume| frames from the FIFO into the destination. If the
FIFO does not have | 64 // Read |framesToConsume| frames from the FIFO into the destination. If the |
| 55 // enough data, we ask the |provider| to get more data to fulfill the reques
t. | 65 // FIFO does not have enough data, it asks the |provider| to get more data |
| 66 // to fulfill the request. |
| 56 void consume(AudioBus* destination, size_t framesToConsume); | 67 void consume(AudioBus* destination, size_t framesToConsume); |
| 57 | 68 |
| 58 private: | 69 private: |
| 59 // Fill the FIFO buffer with at least |numberOfFrames| more data. | 70 // Request more data of |numberOfFrames| from provider to fill the FIFO |
| 60 void fillBuffer(size_t numberOfFrames); | 71 // buffer. |
| 72 void requestDataFromProvider(size_t numberOfFrames); |
| 73 |
| 74 // Number of frames of data that the provider will produce per call. |
| 75 unsigned m_providerRenderBlockSize; |
| 61 | 76 |
| 62 // The provider of the data in our FIFO. | 77 // The provider of the data in our FIFO. |
| 63 AudioSourceProvider& m_provider; | 78 AudioSourceProvider& m_provider; |
| 64 | 79 |
| 65 // The actual FIFO | 80 // Temporary audio bus reference to transfer the data from the provider. |
| 81 RefPtr<AudioBus> m_tempBus; |
| 82 |
| 83 // The actual FIFO. |
| 66 AudioFIFO m_fifo; | 84 AudioFIFO m_fifo; |
| 67 | |
| 68 // Number of frames of data that the provider will produce per call. | |
| 69 unsigned m_providerSize; | |
| 70 | |
| 71 // Temporary workspace to hold the data from the provider. | |
| 72 RefPtr<AudioBus> m_tempBus; | |
| 73 }; | 85 }; |
| 74 | 86 |
| 75 } // namespace blink | 87 } // namespace blink |
| 76 | 88 |
| 77 #endif // AudioPullFIFO.h | 89 #endif // AudioPullFIFO.h |
| OLD | NEW |