4 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
7 * Kitae Kim <kt920.kim@samsung.com>
8 * SeokYeon Hwang <syeon.hwang@samsung.com>
9 * DongKyun Yun <dk77.yun@samsung.com>
10 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
33 #include <sys/types.h>
38 #include "tizen/src/debug_ch.h"
39 #include "maru_pci_ids.h"
41 #include <libavformat/avformat.h>
43 #define CODEC_MAX_CONTEXT 10
46 * Codec Device Structures
49 typedef struct _SVCodecParam {
58 typedef struct _SVCodecContext {
59 AVCodecContext *pAVCtx;
61 AVCodecParserContext *pParserCtx;
62 uint8_t *pParserBuffer;
68 typedef struct _SVCodecState {
70 SVCodecContext ctxArr[CODEC_MAX_CONTEXT];
71 SVCodecParam codecParam;
72 pthread_mutex_t codec_mutex;
84 CODEC_API_INDEX = 0x00,
85 CODEC_IN_PARAM = 0x04,
86 CODEC_RETURN_VALUE = 0x08,
87 CODEC_CONTEXT_INDEX = 0x0c,
88 CODEC_MMAP_OFFSET = 0x10,
89 CODEC_FILE_INDEX = 0x14,
94 EMUL_AV_REGISTER_ALL = 1,
95 EMUL_AVCODEC_ALLOC_CONTEXT,
96 EMUL_AVCODEC_ALLOC_FRAME,
101 EMUL_AV_FREE_PALCTRL,
102 EMUL_AV_FREE_EXTRADATA,
103 EMUL_AVCODEC_FLUSH_BUFFERS,
104 EMUL_AVCODEC_DECODE_VIDEO,
105 EMUL_AVCODEC_ENCODE_VIDEO,
106 EMUL_AVCODEC_DECODE_AUDIO,
107 EMUL_AVCODEC_ENCODE_AUDIO,
108 EMUL_AV_PICTURE_COPY,
110 EMUL_AV_PARSER_PARSE,
111 EMUL_AV_PARSER_CLOSE,
118 int codec_init (PCIBus *bus);
120 uint64_t codec_read (void *opaque, target_phys_addr_t addr, unsigned size);
122 void codec_write (void *opaque, target_phys_addr_t addr, uint64_t value, unsigned size);
124 static int codec_operate(uint32_t apiIndex, uint32_t ctxIndex, SVCodecState *state);
129 static void qemu_parser_init (SVCodecState *s, int ctxIndex);
131 static void qemu_restore_context (AVCodecContext *dst, AVCodecContext *src);
137 static void qemu_av_register_all (void);
139 static int qemu_avcodec_open (SVCodecState *s, int ctxIndex);
141 static int qemu_avcodec_close (SVCodecState *s, int ctxIndex);
143 static void qemu_avcodec_alloc_context (SVCodecState *s);
145 static void qemu_avcodec_alloc_frame (SVCodecState *s);
147 static void qemu_av_free_context (SVCodecState* s, int ctxIndex);
149 static void qemu_av_free_picture (SVCodecState* s, int ctxIndex);
151 static void qemu_av_free_palctrl (SVCodecState* s, int ctxIndex);
153 static void qemu_av_free_extradata (SVCodecState* s, int ctxIndex);
155 static void qemu_avcodec_flush_buffers (SVCodecState *s, int ctxIndex);
157 static int qemu_avcodec_decode_video (SVCodecState *s, int ctxIndex);
159 static int qemu_avcodec_encode_video (SVCodecState *s, int ctxIndex);
161 static int qemu_avcodec_decode_audio (SVCodecState *s, int ctxIndex);
163 static int qemu_avcodec_encode_audio (SVCodecState *s, int ctxIndex);
165 static void qemu_av_picture_copy (SVCodecState *s, int ctxIndex);
167 static void qemu_av_parser_init (SVCodecState *s, int ctxIndex);
169 static int qemu_av_parser_parse (SVCodecState *s, int ctxIndex);
171 static void qemu_av_parser_close (SVCodecState *s, int ctxIndex);
173 static int qemu_avcodec_get_buffer (AVCodecContext *context, AVFrame *picture);
175 static void qemu_avcodec_release_buffer (AVCodecContext *context, AVFrame *picture);