static LRESULT CALLBACK videostream_cb(HWND hwnd, LPVIDEOHDR vdhdr) { AVFormatContext *s; struct vfw_ctx *ctx; AVPacketList **ppktl, *pktl_next; s = (AVFormatContext *) GetWindowLongPtr(hwnd, GWLP_USERDATA); ctx = s->priv_data; dump_videohdr(s, vdhdr); if(shall_we_drop(s)) return FALSE; WaitForSingleObject(ctx->mutex, INFINITE); pktl_next = av_mallocz(sizeof(AVPacketList)); if(!pktl_next) goto fail; if(av_new_packet(&pktl_next->pkt, vdhdr->dwBytesUsed) < 0) { av_free(pktl_next); goto fail; } pktl_next->pkt.pts = vdhdr->dwTimeCaptured; memcpy(pktl_next->pkt.data, vdhdr->lpData, vdhdr->dwBytesUsed); for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next); *ppktl = pktl_next; ctx->curbufsize += vdhdr->dwBytesUsed; SetEvent(ctx->event); ReleaseMutex(ctx->mutex); return TRUE; fail: ReleaseMutex(ctx->mutex); return FALSE; }
static void callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time) { AVFormatContext *s = priv_data; struct dshow_ctx *ctx = s->priv_data; AVPacketList **ppktl, *pktl_next; // dump_videohdr(s, vdhdr); WaitForSingleObject(ctx->mutex, INFINITE); if(shall_we_drop(s)) goto fail; pktl_next = av_mallocz(sizeof(AVPacketList)); if(!pktl_next) goto fail; if(av_new_packet(&pktl_next->pkt, buf_size) < 0) { av_free(pktl_next); goto fail; } pktl_next->pkt.stream_index = index; pktl_next->pkt.pts = time; memcpy(pktl_next->pkt.data, buf, buf_size); for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next); *ppktl = pktl_next; ctx->curbufsize += buf_size; SetEvent(ctx->event); ReleaseMutex(ctx->mutex); return; fail: ReleaseMutex(ctx->mutex); return; }