[Title] Solved the problem when multimedia apps have been killed abnormally.
authorKitae Kim <kt920.kim@samsung.com>
Fri, 6 Apr 2012 18:24:42 +0000 (03:24 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Fri, 6 Apr 2012 18:24:42 +0000 (03:24 +0900)
[Type] bug fix
[Module] emulator / codec
[Priority]
[CQ#]
[Redmine#]
[Problem]
[Cause]
[Solution] Uses pointer addr of struct file as a unique id
[TestCase]

tizen/src/hw/maru_codec.c
tizen/src/hw/maru_codec.h

index 1454121..13def61 100644 (file)
@@ -57,6 +57,27 @@ static void qemu_parser_init (SVCodecState *s, int ctxIndex)
     TRACE("[%s] Leave\n", __func__);
 }
 
+static void qemu_codec_close (SVCodecState *s, uint32_t value)
+{
+    int i, ctxIndex;
+    TRACE("[%s] Enter\n", __func__);
+
+    pthread_mutex_lock(&s->codec_mutex);
+    for (i = 0; i < CODEC_MAX_CONTEXT; i++) {
+        if (s->ctxArr[i].nFileValue == value) {
+            ctxIndex = i;
+            break;
+        }
+    }
+
+    TRACE("[%s] Close %d context\n", __func__, ctxIndex);
+
+    s->ctxArr[ctxIndex].bUsed = false;
+    pthread_mutex_unlock(&s->codec_mutex);
+
+    TRACE("[%s] Leave\n", __func__);
+}
+
 static void qemu_restore_context (AVCodecContext *dst, AVCodecContext *src) {
     TRACE("[%s] Enter\n", __func__);
 
@@ -376,6 +397,7 @@ static void qemu_avcodec_alloc_context (SVCodecState* s)
     TRACE("[%s] context index :%d.\n", __func__, ctxArrIndex);
 
     s->ctxArr[ctxArrIndex].pAVCtx = avcodec_alloc_context();
+    s->ctxArr[ctxArrIndex].nFileValue = s->codecParam.fileIndex;
     s->ctxArr[ctxArrIndex].bUsed = true;
     memcpy((uint8_t*)s->vaddr + offset, &ctxArrIndex, sizeof(int));
     qemu_parser_init(s, ctxArrIndex);
@@ -423,7 +445,6 @@ static void qemu_av_free_picture (SVCodecState* s, int ctxIndex)
         av_free(avframe);
         s->ctxArr[ctxIndex].pFrame = NULL;
     }
-    s->ctxArr[ctxIndex].bUsed = false;
 
     pthread_mutex_unlock(&s->codec_mutex);
     TRACE("free AVFrame\n");
@@ -1187,7 +1208,7 @@ uint64_t codec_read (void *opaque, target_phys_addr_t addr, unsigned size)
 {
     switch (addr) {
         default:
-            ERR("There is no avaiable command for svcodece\n");
+            ERR("There is no avaiable command for %s\n", QEMU_DEV_NAME);
     }
     return 0;
 }
@@ -1223,6 +1244,12 @@ void codec_write (void *opaque, target_phys_addr_t addr, uint64_t value, unsigne
             state->codecParam.mmapOffset = value * MARU_CODEC_MMAP_MEM_SIZE;
             TRACE("MMAP Offset :%d\n", state->codecParam.mmapOffset);
             break;
+        case CODEC_FILE_INDEX:
+            state->codecParam.fileIndex = value;
+            break;
+        case CODEC_CLOSED:
+            qemu_codec_close(state, value);
+            break;
         default:
             ERR("There is no avaiable command for %s\n", QEMU_DEV_NAME);
     }
@@ -1239,6 +1266,8 @@ static int codec_initfn (PCIDevice *dev)
     SVCodecState *s = DO_UPCAST(SVCodecState, dev, dev);
     uint8_t *pci_conf = s->dev.config;
 
+    INFO("[%s] device init\n", __func__);
+
     memset(&s->codecParam, 0x00, sizeof(SVCodecParam));
     pthread_mutex_init(&s->codec_mutex, NULL);
  
@@ -1258,6 +1287,7 @@ static int codec_initfn (PCIDevice *dev)
 static int codec_exitfn (PCIDevice *dev)
 {
     SVCodecState *s = DO_UPCAST(SVCodecState, dev, dev);
+    INFO("[%s] device exit\n", __func__);
 
     memory_region_destroy (&s->vram);
     memory_region_destroy (&s->mmio);
@@ -1266,7 +1296,7 @@ static int codec_exitfn (PCIDevice *dev)
 
 int codec_init (PCIBus *bus)
 {
-    INFO("[%s] device init\n", __func__);
+    INFO("[%s] device create\n", __func__);
     pci_create_simple (bus, -1, QEMU_DEV_NAME);
     return 0;
 }
index 75e597d..be7cac5 100644 (file)
@@ -53,6 +53,7 @@ typedef struct _SVCodecParam {
     uint32_t        in_args[20];
     uint32_t        ret_args;
     uint32_t        mmapOffset;
+    uint32_t        fileIndex;
 } SVCodecParam;
 
 typedef struct _SVCodecContext {
@@ -62,6 +63,7 @@ typedef struct _SVCodecContext {
     uint8_t                 *pParserBuffer;
     bool                    bParser;
     bool                    bUsed;
+    uint32_t                nFileValue;
 } SVCodecContext;
 
 typedef struct _SVCodecState {
@@ -71,13 +73,12 @@ typedef struct _SVCodecState {
     pthread_mutex_t     codec_mutex;
 
     int                 mmioIndex;
-
     uint32_t            mem_addr;
     uint32_t            mmio_addr;
 
     uint8_t*            vaddr;
     MemoryRegion        vram;
-       MemoryRegion            mmio;
+    MemoryRegion        mmio;
 } SVCodecState;
 
 enum {
@@ -86,6 +87,8 @@ enum {
     CODEC_RETURN_VALUE      = 0x08,
     CODEC_CONTEXT_INDEX     = 0x0c,
     CODEC_MMAP_OFFSET       = 0x10,
+    CODEC_FILE_INDEX        = 0x14,
+    CODEC_CLOSED            = 0x18,
 };
 
 enum {