static void _call_enter(PyObject *self, PyFrameObject *frame, PyObject *arg, int ccall) { _pit *cp,*pp; _cstackitem *ci; _pit_children_info *pci; if (ccall) { cp = _ccode2pit((PyCFunctionObject *)arg); } else { cp = _code2pit(frame); } // something went wrong. No mem, or another error. we cannot find // a corresponding pit. just run away:) if (!cp) { _log_err(4); return; } // create/update children info if we have a valid parent pp = _get_frame(); if (pp) { pci = _get_child_info(pp, cp); if(!pci) { pci = _add_child_info(pp, cp); } pci->callcount++; incr_rec_level((uintptr_t)pci); } ci = _push_frame(cp); if (!ci) { // runaway! (defensive) _log_err(5); return; } ci->t0 = tickcount(); cp->callcount++; incr_rec_level((uintptr_t)cp); }
static void _call_leave(PyObject *self, PyFrameObject *frame, PyObject *arg, int ccall) { long long elapsed; _pit *cp, *pp, *ppp; _pit_children_info *pci,*ppci; elapsed = _get_frame_elapsed(); // leaving a frame while callstack is empty? cp = _pop_frame(); if (!cp) { return; } // is this the last function in the callstack? pp = _pop_frame(); if (!pp) { cp->ttotal += elapsed; cp->tsubtotal += elapsed; cp->nonrecursive_callcount++; decr_rec_level((uintptr_t)cp); return; } // get children info pci = _get_child_info(pp, cp); if(!pci) { _log_err(6); return; // defensive } // a calls b. b's elapsed time is subtracted from a's tsub and a adds its own elapsed it is leaving. pp->tsubtotal -= elapsed; cp->tsubtotal += elapsed; // a calls b calls c. child c's elapsed time is subtracted from child b's tsub and child b adds its // own elapsed when it is leaving ppp = _get_frame(); if (ppp) { ppci = _get_child_info(ppp, pp); if(!ppci) { _log_err(7); return; } ppci->tsubtotal -= elapsed; } pci->tsubtotal += elapsed; // wait for the top-level function/parent/child to update timing values accordingly. if (get_rec_level((uintptr_t)cp) == 1) { cp->ttotal += elapsed; cp->nonrecursive_callcount++; pci->nonrecursive_callcount++; } if (get_rec_level((uintptr_t)pci) == 1) { pci->ttotal += elapsed; } decr_rec_level((uintptr_t)pci); decr_rec_level((uintptr_t)cp); if (!_push_frame(pp)) { _log_err(8); return; //defensive } }
size_t audio_decoder_get_frames(audio_decoder_p decoder, unsigned char *buf, size_t max, unsigned int *sr, unsigned short *ch) { priv_data_p priv = (priv_data_p) decoder->priv_data; pcm_data_p pcm = &priv->pcm; // Output size, in bytes size_t size = 0; // Check 2 bytes aligned, due to 16bit-PCM format. assert((max % 2) == 0); while (size < max) { if (pcm->samples) { // Copy remained data to decoder output buffer size_t nSamples = (max - size) / BYTES_PER_SAMPLE; if (pcm->length <= nSamples) { // Copy all data memcpy(buf + size, pcm->samples, pcm->length * BYTES_PER_SAMPLE); size += pcm->length * BYTES_PER_SAMPLE; // Clear remained data record pcm->samples = NULL; pcm->length = 0; continue; } else { // Copy part of data required memcpy(buf + size, pcm->samples, nSamples * BYTES_PER_SAMPLE); size = max; // Update remained data record pcm->samples += nSamples; pcm->length -= nSamples; break; } } // Decode more if (!_get_frame(decoder)) { // Need to push more data for further decoding. // In this case, *size < max. medvdbg("there's not enough data, need to push more.\n"); break; } if (_frame_decoder(decoder, pcm) != AUDIO_DECODER_OK) { // Decoding failed meddbg("frame decoding failed!\n"); break; } } // Output sample rate if desired if (sr != NULL) { *sr = pcm->samplerate; } // Output channel num if desired if (ch != NULL) { *ch = pcm->channels; } return size; }