gstvp8dec.c 5.05 KB
Newer Older
1
/* VP8
2 3
 * Copyright (C) 2006 David Schleef <ds@schleef.org>
 * Copyright (C) 2008,2009,2010 Entropy Wave Inc
4
 * Copyright (C) 2010-2012 Sebastian Dröge <sebastian.droege@collabora.co.uk>
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
18 19
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
20 21
 *
 */
22 23 24 25 26 27 28 29 30 31 32 33 34
/**
 * SECTION:element-vp8dec
 * @see_also: vp8enc, matroskademux
 *
 * This element decodes VP8 streams into raw video.
 * <ulink url="http://www.webmproject.org">VP8</ulink> is a royalty-free
 * video codec maintained by <ulink url="http://www.google.com/">Google
 * </ulink>. It's the successor of On2 VP3, which was the base of the
 * Theora video codec.
 *
 * <refsect2>
 * <title>Example pipeline</title>
 * |[
35
 * gst-launch-1.0 -v filesrc location=videotestsrc.webm ! matroskademux ! vp8dec ! videoconvert ! videoscale ! autovideosink
36 37 38
 * ]| This example pipeline will decode a WebM stream and decodes the VP8 video.
 * </refsect2>
 */
39 40 41 42 43

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

44 45
#ifdef HAVE_VP8_DECODER

46 47
#include <string.h>

48
#include "gstvp8dec.h"
49
#include "gstvp8utils.h"
50

51 52 53
#include <gst/video/gstvideometa.h>
#include <gst/video/gstvideopool.h>

54
GST_DEBUG_CATEGORY_STATIC (gst_vp8dec_debug);
55 56
#define GST_CAT_DEFAULT gst_vp8dec_debug

57
#define VP8_DECODER_VIDEO_TAG "VP8 video"
58

59 60 61 62
static void gst_vp8_dec_set_default_format (GstVPXDec * dec, GstVideoFormat fmt,
    int width, int height);
static void gst_vp8_dec_handle_resolution_change (GstVPXDec * dec,
    vpx_image_t * img, GstVideoFormat fmt);
63 64 65 66 67 68 69 70 71 72 73 74

static GstStaticPadTemplate gst_vp8_dec_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
    GST_PAD_SINK,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("video/x-vp8")
    );

static GstStaticPadTemplate gst_vp8_dec_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_ALWAYS,
75
    GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("I420"))
76 77
    );

78
#define parent_class gst_vp8_dec_parent_class
79
G_DEFINE_TYPE (GstVP8Dec, gst_vp8_dec, GST_TYPE_VPX_DEC);
80 81 82 83

static void
gst_vp8_dec_class_init (GstVP8DecClass * klass)
{
84
  GstElementClass *element_class;
85
  GstVPXDecClass *vpx_class;
86

87
  element_class = GST_ELEMENT_CLASS (klass);
88
  vpx_class = GST_VPX_DEC_CLASS (klass);
89

90 91 92 93
  gst_element_class_add_static_pad_template (element_class,
      &gst_vp8_dec_sink_template);
  gst_element_class_add_static_pad_template (element_class,
      &gst_vp8_dec_src_template);
94

95
  gst_element_class_set_static_metadata (element_class,
96 97
      "On2 VP8 Decoder",
      "Codec/Decoder/Video",
98 99
      "Decode VP8 video streams", "David Schleef <ds@entropywave.com>, "
      "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
100

101 102 103 104 105 106
  vpx_class->video_codec_tag = VP8_DECODER_VIDEO_TAG;
  vpx_class->codec_algo = &vpx_codec_vp8_dx_algo;
  vpx_class->set_default_format =
      GST_DEBUG_FUNCPTR (gst_vp8_dec_set_default_format);
  vpx_class->handle_resolution_change =
      GST_DEBUG_FUNCPTR (gst_vp8_dec_handle_resolution_change);
107 108

  GST_DEBUG_CATEGORY_INIT (gst_vp8dec_debug, "vp8dec", 0, "VP8 Decoder");
109 110 111
}

static void
112
gst_vp8_dec_init (GstVP8Dec * gst_vp8_dec)
113
{
114
  GST_DEBUG_OBJECT (gst_vp8_dec, "gst_vp8_dec_init");
115 116 117
}

static void
118 119
gst_vp8_dec_set_default_format (GstVPXDec * dec, GstVideoFormat fmt, int width,
    int height)
120
{
121
  GstVPXDecClass *vpxclass = GST_VPX_DEC_GET_CLASS (dec);
122 123 124
  g_assert (dec->output_state == NULL);
  dec->output_state =
      gst_video_decoder_set_output_state (GST_VIDEO_DECODER (dec),
125
      GST_VIDEO_FORMAT_I420, width, height, dec->input_state);
126
  gst_video_decoder_negotiate (GST_VIDEO_DECODER (dec));
127
  vpxclass->send_tags (dec);
128
}
129

130 131 132
static void
gst_vp8_dec_handle_resolution_change (GstVPXDec * dec, vpx_image_t * img,
    GstVideoFormat fmt)
133
{
134 135
  GstVideoInfo *info;
  GstVideoCodecState *new_output_state;
136

137 138 139 140 141 142 143 144 145 146 147 148 149
  info = &dec->output_state->info;
  if (GST_VIDEO_INFO_WIDTH (info) != img->d_w
      || GST_VIDEO_INFO_HEIGHT (info) != img->d_h) {
    GST_DEBUG_OBJECT (dec,
        "Changed output resolution was %d x %d now is got %u x %u (display %u x %u)",
        GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info), img->w,
        img->h, img->d_w, img->d_h);

    new_output_state =
        gst_video_decoder_set_output_state (GST_VIDEO_DECODER (dec),
        GST_VIDEO_FORMAT_I420, img->d_w, img->d_h, dec->output_state);
    if (dec->output_state) {
      gst_video_codec_state_unref (dec->output_state);
150
    }
151 152 153
    dec->output_state = new_output_state;
    /* No need to call negotiate() here, it will be automatically called
     * by allocate_output_frame()*/
154
  }
155 156
}

157
#endif /* HAVE_VP8_DECODER */