[media] coda: reuse src_bufs in coda_job_ready
[deliverable/linux.git] / drivers / media / platform / coda / coda-common.c
index 58f65486de332cd893d6175ad98ca405c999a221..267fda760b38d14c5a5987d2479f61077d198a35 100644 (file)
@@ -61,11 +61,6 @@ int coda_debug;
 module_param(coda_debug, int, 0644);
 MODULE_PARM_DESC(coda_debug, "Debug level (0-2)");
 
-struct coda_fmt {
-       char *name;
-       u32 fourcc;
-};
-
 void coda_write(struct coda_dev *dev, u32 data, u32 reg)
 {
        v4l2_dbg(2, coda_debug, &dev->v4l2_dev,
@@ -111,40 +106,6 @@ void coda_write_base(struct coda_ctx *ctx, struct coda_q_data *q_data,
        coda_write(ctx->dev, base_cr, reg_y + 8);
 }
 
-/*
- * Array of all formats supported by any version of Coda:
- */
-static const struct coda_fmt coda_formats[] = {
-       {
-               .name = "YUV 4:2:0 Planar, YCbCr",
-               .fourcc = V4L2_PIX_FMT_YUV420,
-       },
-       {
-               .name = "YUV 4:2:0 Planar, YCrCb",
-               .fourcc = V4L2_PIX_FMT_YVU420,
-       },
-       {
-               .name = "YUV 4:2:0 Partial interleaved Y/CbCr",
-               .fourcc = V4L2_PIX_FMT_NV12,
-       },
-       {
-               .name = "YUV 4:2:2 Planar, YCbCr",
-               .fourcc = V4L2_PIX_FMT_YUV422P,
-       },
-       {
-               .name = "H264 Encoded Stream",
-               .fourcc = V4L2_PIX_FMT_H264,
-       },
-       {
-               .name = "MPEG4 Encoded Stream",
-               .fourcc = V4L2_PIX_FMT_MPEG4,
-       },
-       {
-               .name = "JPEG Encoded Images",
-               .fourcc = V4L2_PIX_FMT_JPEG,
-       },
-};
-
 #define CODA_CODEC(mode, src_fourcc, dst_fourcc, max_w, max_h) \
        { mode, src_fourcc, dst_fourcc, max_w, max_h }
 
@@ -261,40 +222,23 @@ static const struct coda_video_device *coda9_video_devices[] = {
        &coda_bit_decoder,
 };
 
-static bool coda_format_is_yuv(u32 fourcc)
+/*
+ * Normalize all supported YUV 4:2:0 formats to the value used in the codec
+ * tables.
+ */
+static u32 coda_format_normalize_yuv(u32 fourcc)
 {
        switch (fourcc) {
        case V4L2_PIX_FMT_YUV420:
        case V4L2_PIX_FMT_YVU420:
        case V4L2_PIX_FMT_NV12:
        case V4L2_PIX_FMT_YUV422P:
-               return true;
+               return V4L2_PIX_FMT_YUV420;
        default:
-               return false;
+               return fourcc;
        }
 }
 
-static const char *coda_format_name(u32 fourcc)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(coda_formats); i++) {
-               if (coda_formats[i].fourcc == fourcc)
-                       return coda_formats[i].name;
-       }
-
-       return NULL;
-}
-
-/*
- * Normalize all supported YUV 4:2:0 formats to the value used in the codec
- * tables.
- */
-static u32 coda_format_normalize_yuv(u32 fourcc)
-{
-       return coda_format_is_yuv(fourcc) ? V4L2_PIX_FMT_YUV420 : fourcc;
-}
-
 static const struct coda_codec *coda_find_codec(struct coda_dev *dev,
                                                int src_fourcc, int dst_fourcc)
 {
@@ -396,7 +340,6 @@ static int coda_enum_fmt(struct file *file, void *priv,
        struct video_device *vdev = video_devdata(file);
        const struct coda_video_device *cvd = to_coda_video_device(vdev);
        const u32 *formats;
-       const char *name;
 
        if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
                formats = cvd->src_formats;
@@ -408,11 +351,7 @@ static int coda_enum_fmt(struct file *file, void *priv,
        if (f->index >= CODA_MAX_FORMATS || formats[f->index] == 0)
                return -EINVAL;
 
-       name = coda_format_name(formats[f->index]);
-       strlcpy(f->description, name, sizeof(f->description));
        f->pixelformat = formats[f->index];
-       if (!coda_format_is_yuv(formats[f->index]))
-               f->flags |= V4L2_FMT_FLAG_COMPRESSED;
 
        return 0;
 }
@@ -949,14 +888,14 @@ static void coda_pic_run_work(struct work_struct *work)
 static int coda_job_ready(void *m2m_priv)
 {
        struct coda_ctx *ctx = m2m_priv;
+       int src_bufs = v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx);
 
        /*
         * For both 'P' and 'key' frame cases 1 picture
         * and 1 frame are needed. In the decoder case,
         * the compressed frame can be in the bitstream.
         */
-       if (!v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) &&
-           ctx->inst_type != CODA_INST_DECODER) {
+       if (!src_bufs && ctx->inst_type != CODA_INST_DECODER) {
                v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
                         "not ready: not enough video buffers.\n");
                return 0;
@@ -972,9 +911,8 @@ static int coda_job_ready(void *m2m_priv)
                struct list_head *meta;
                bool stream_end;
                int num_metas;
-               int src_bufs;
 
-               if (ctx->hold && !v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx)) {
+               if (ctx->hold && !src_bufs) {
                        v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
                                 "%d: not ready: on hold for more buffers.\n",
                                 ctx->idx);
@@ -988,8 +926,6 @@ static int coda_job_ready(void *m2m_priv)
                list_for_each(meta, &ctx->buffer_meta_list)
                        num_metas++;
 
-               src_bufs = v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx);
-
                if (!stream_end && (num_metas + src_bufs) < 2) {
                        v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
                                 "%d: not ready: need 2 buffers available (%d, %d)\n",
@@ -998,8 +934,8 @@ static int coda_job_ready(void *m2m_priv)
                }
 
 
-               if (!v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) &&
-                   !stream_end && (coda_get_bitstream_payload(ctx) < 512)) {
+               if (!src_bufs && !stream_end &&
+                   (coda_get_bitstream_payload(ctx) < 512)) {
                        v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
                                 "%d: not ready: not enough bitstream data (%d).\n",
                                 ctx->idx, coda_get_bitstream_payload(ctx));
@@ -1244,9 +1180,7 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
 
        q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
        if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
-               if (q_data_src->fourcc == V4L2_PIX_FMT_H264 ||
-                   (q_data_src->fourcc == V4L2_PIX_FMT_JPEG &&
-                    ctx->dev->devtype->product == CODA_7541)) {
+               if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit) {
                        /* copy the buffers that were queued before streamon */
                        mutex_lock(&ctx->bitstream_mutex);
                        coda_fill_bitstream(ctx, false);
@@ -1315,7 +1249,6 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
                        goto err;
        }
 
-       ctx->initialized = 1;
        return ret;
 
 err:
@@ -1378,10 +1311,12 @@ static void coda_stop_streaming(struct vb2_queue *q)
                mutex_unlock(&ctx->bitstream_mutex);
                kfifo_init(&ctx->bitstream_fifo,
                        ctx->bitstream.vaddr, ctx->bitstream.size);
-               ctx->initialized = 0;
                ctx->runcounter = 0;
                ctx->aborting = 0;
        }
+
+       if (!ctx->streamon_out && !ctx->streamon_cap)
+               ctx->bit_stream_param &= ~CODA_BIT_STREAM_END_FLAG;
 }
 
 static const struct vb2_ops coda_qops = {
@@ -1769,7 +1704,7 @@ static int coda_release(struct file *file)
        v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
 
        /* In case the instance was not running, we still need to call SEQ_END */
-       if (ctx->initialized && ctx->ops->seq_end_work) {
+       if (ctx->ops->seq_end_work) {
                queue_work(dev->workqueue, &ctx->seq_end_work);
                flush_work(&ctx->seq_end_work);
        }
This page took 0.025569 seconds and 5 git commands to generate.