MCPcopy Create free account
hub / github.com/alibaba/CicadaPlayer / write_callback

Method write_callback

framework/data_source/curl/CURLConnection.cpp:208–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206}
207
208size_t Cicada::CURLConnection::write_callback(char *buffer, size_t size, size_t nitems, void *userp)
209{
210 CURLConnection *pHandle = (CURLConnection *) userp;
211 uint32_t amount = (uint32_t) (size * nitems);
212
213 if (pHandle->mPConfig && pHandle->mPConfig->listener) {
214 // TODO: get file type form content type
215 pHandle->mPConfig->listener->onNetWorkInPut(amount, IDataSource::Listener::bitStreamTypeMedia);
216 }
217
218 if (pHandle->overflowSize) {
219 // we have our overflow buffer - first get rid of as much as we can
220 uint32_t maxWriteable = std::min(RingBuffergetMaxWriteSize(pHandle->pRbuf), pHandle->overflowSize);
221
222 if (maxWriteable) {
223 if (RingBufferWriteData(pHandle->pRbuf, pHandle->pOverflowBuffer, maxWriteable) != maxWriteable) {
224 AF_LOGE("write ring buffer error\n");
225 }
226
227 if (pHandle->overflowSize > maxWriteable) { // still have some more - copy it down
228 memmove(pHandle->pOverflowBuffer, pHandle->pOverflowBuffer + maxWriteable, pHandle->overflowSize - maxWriteable);
229 }
230
231 pHandle->overflowSize -= maxWriteable;
232 }
233 }
234
235 uint32_t maxWriteable = std::min(RingBuffergetMaxWriteSize(pHandle->pRbuf), amount);
236
237 if (maxWriteable) {
238 if (RingBufferWriteData(pHandle->pRbuf, buffer, maxWriteable) != maxWriteable) {
239 AF_LOGE("write ring buffer error\n");
240 } else {
241 amount -= maxWriteable;
242 buffer += maxWriteable;
243 }
244 }
245
246 if (amount) {
247 char *p = (char *) realloc(pHandle->pOverflowBuffer, pHandle->overflowSize + amount);
248
249 if (p == nullptr) {
250 AF_LOGE("av_realloc error\n");
251 return -ENOMEM;
252 }
253
254 pHandle->pOverflowBuffer = p;
255 memcpy(pHandle->pOverflowBuffer + pHandle->overflowSize, buffer, amount);
256 pHandle->overflowSize += amount;
257 }
258 pHandle->mWriteSize += size * nitems;
259 return size * nitems;
260}
261
262void Cicada::CURLConnection::debugHeader(bool in, char *data, size_t size)
263{

Callers

nothing calls this directly

Calls 4

minClass · 0.85
RingBufferWriteDataFunction · 0.85
onNetWorkInPutMethod · 0.45

Tested by

no test coverage detected