JNIEXPORT void Java_com_dropcam_android_media_H264Decoder_nativeInit(JNIEnv* env, jobject thiz, jint color_format) { DecoderContext *ctx = calloc(1, sizeof(DecoderContext)); D("Creating native H264 decoder context"); switch (color_format) { case COLOR_FORMAT_YUV420: ctx->color_format = PIX_FMT_YUV420P; break; case COLOR_FORMAT_RGB565LE: ctx->color_format = PIX_FMT_RGB565LE; break; case COLOR_FORMAT_BGR32: ctx->color_format = PIX_FMT_BGR32; break; } ctx->codec = avcodec_find_decoder(CODEC_ID_H264); ctx->codec_ctx = avcodec_alloc_context3(ctx->codec); ctx->codec_ctx->pix_fmt = PIX_FMT_YUV420P; ctx->codec_ctx->flags2 |= CODEC_FLAG2_CHUNKS; ctx->src_frame = av_frame_alloc(); ctx->dst_frame = av_frame_alloc(); avcodec_open2(ctx->codec_ctx, ctx->codec, NULL); set_ctx(env, thiz, ctx); }
int hdd_io(int hdd_n, void *buff, u16 sectors, u64 start, int read) { u8 sbuf[32]; rm_ctx ctx; u32 head, cyl; u8 dos_n = hdd2dos(hdd_n); hdd_inf *hdd = &iodb.p_hdd[hdd_n]; lba_p *lba = pv(0x580); /* this needed for avoid stupid actions by buggy BIOSes */ int succs = 0; /* setup initial context */ set_ctx(0, &ctx); if (hdd->flags & HDD_LBA) { /* save old buffer */ mincpy(sbuf, lba, sizeof(sbuf)); /* setup LBA block */ lba->size = sizeof(lba_p); lba->unk = 0; lba->dst_sel = rm_seg(buff); lba->dst_off = rm_off(buff); lba->numb = sectors; lba->sector = start; ctx.ah = read ? 0x42:0x43; ctx.dl = dos_n; ctx.si = 0x180; ctx.ds = 0x40; /* if DS can be 0x40, we can avoid AWARD BIOS bug of int13/AX=4B01 */ /* set additional registers to serve buggy BIOSes. */ ctx.es = ctx.ds; ctx.di = ctx.si; ctx.bx = ctx.si; ctx.cx = ctx.ds; /* do not check AH because some buggy USB BIOSes fail to clear AH on success */ succs = bios_call(0x13, &ctx); /* restore saved buffer */ mincpy(lba, sbuf, sizeof(sbuf)); } else { head = d32(start) / hdd->max_sect; cyl = head / hdd->max_head; ctx.ah = read ? 0x02:0x03; ctx.al = d8(sectors); ctx.ch = d8(cyl); ctx.cl = d8(((cyl & 0x0300) >> 2) | (d32(start) % hdd->max_sect + 1)); ctx.dh = head % hdd->max_head; ctx.dl = dos_n; ctx.es = rm_seg(buff); ctx.bx = rm_off(buff); /* do not check AH because some buggy USB BIOSes fail to clear AH on success */ succs = bios_call(0x13, &ctx); } return succs; }