- 论坛徽章:
- 11
|
本帖最后由 zylthinking 于 2014-12-30 21:50 编辑
嗯, 问题是没办法解释.............
push 只有一个调用方, mbuf 是调用方 malloc 出来的, 而后通过 push 挂到链表上
static int push(void* any, char* buf, unsigned int length)
{
struct capture_context* ctx = (struct capture_context *) any;
if (buf == NULL) {
return 0;
}
struct my_buffer* mbuf = (struct my_buffer *) buf;
media_buffer* media = (media_buffer *) mbuf->ptr[0];
if (ctx->bytes_per_ms.num == 0) {
audio_format* fmt = to_audio_format(media->pptr_cc);
ctx->align = fmt->pcm->sambits / 8;
ctx->bytes_per_ms = pcm_bytes_from_ms(fmt->pcm, 1);
}
lock(&ctx->lck);
if (ctx->ref == 2) {
list_add_tail(&mbuf->head, &ctx->head);
} else {
mbuf->mop->free(mbuf);
}
unlock(&ctx->lck);
return 0;
}回复 2# koolcoy
static int input_read(void* any, struct list_head* headp, const fraction* f)
{
struct capture_context* ctx = (struct capture_context *) any;
if (ctx->bytes_per_ms.num == 0) {
return 0;
}
uint32_t bytes = f->num;
if (bytes != (uint32_t) -1) {
bytes = (ctx->bytes_per_ms.num * f->num) / (ctx->bytes_per_ms.den * f->den);
bytes = roundup(bytes, ctx->align);
}
int32_t readed = 0;
lock(&ctx->lck);
while (!list_empty(&ctx->head)) {
struct list_head* ent = ctx->head.next;
list_del(ent); -------------------------------> 现象是 list_del 居然没有起作用, 导致 ent 仍然在 链表里挂着
logmsg("%p<----%p---->%p\n", ent->prev, ent, ent->next);
print_list(&ctx->head, "1: ");
struct my_buffer* mbuf = list_entry(ent, struct my_buffer, head);
if (__builtin_expect(mbuf->length <= bytes, 1)) {
logmsg("encode %d bytes\n", mbuf->length);
bytes -= mbuf->length;
readed += encode(ctx, mbuf, headp); --------------------> mbuf 在这里会被 free 掉, 由于 list_del 没有起作用, 导致了 free 了 两次
logmsg("readed = %d\n", readed);
if (bytes == 0) {
break;
}
continue;
}
unlock(&ctx->lck);
struct my_buffer* mbuf2 = mbuf->mop->clone(mbuf); -------------> 这里可以肯定不会走到, 日志输出也显示没有走到这里,
if (mbuf2 != NULL) {
mbuf2->length = bytes;
readed += encode(ctx, mbuf2, headp);
}
uint32_t ms = (bytes * ctx->bytes_per_ms.den) / ctx->bytes_per_ms.num;
media_buffer* media = (media_buffer *) mbuf->ptr[0];
media->pts += ms;
mbuf->length -= bytes;
mbuf->ptr[1] += bytes;
lock(&ctx->lck);
if (ctx->ref == 2) {
list_add(ent, &ctx->head);
} else {
mbuf->mop->free(mbuf);
}
break;
}
if (f->num == (uint32_t) -1) {
readed += encode(ctx, NULL, headp);
}
unlock(&ctx->lck);
return (int) readed;
}
|
|