Merge branch 'master' into 0.11
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 10 Feb 2012 15:46:50 +0000 (16:46 +0100)
committerWim Taymans <wim.taymans@collabora.co.uk>
Fri, 10 Feb 2012 15:46:50 +0000 (16:46 +0100)
Conflicts:
ext/chromaprint/gstchromaprint.c
ext/mpeg2enc/Makefile.am
ext/voaacenc/gstvoaacenc.c
gst/dvbsuboverlay/gstdvbsuboverlay.c
gst/mpegtsdemux/mpegtsbase.c
gst/sdp/gstsdpdemux.c
gst/videoparsers/gsth264parse.c
sys/d3dvideosink/d3dvideosink.c
tests/examples/camerabin/gst-camera-perf.c
tests/examples/camerabin/gst-camerabin-test.c
tests/examples/camerabin2/gst-camerabin2-test.c
tests/examples/mxf/mxfdemux-structure.c
tests/examples/scaletempo/demo-main.c

58 files changed:
1  2 
ext/cog/gstcogmse.c
ext/curl/gstcurlsink.c
ext/faad/gstfaad.c
ext/kate/gstkateenc.c
ext/kate/gstkateparse.c
ext/kate/gstkatetiger.c
ext/kate/gstkateutil.c
ext/kate/gstkateutil.h
ext/modplug/gstmodplug.cc
ext/mpeg2enc/Makefile.am
ext/mpeg2enc/gstmpeg2enc.cc
ext/mplex/gstmplex.cc
ext/opus/gstopusenc.c
ext/resindvd/resindvdbin.c
ext/resindvd/resindvdsrc.c
ext/resindvd/rsnparsetter.c
ext/schroedinger/gstschrodec.c
ext/schroedinger/gstschroenc.c
ext/sdl/sdlaudiosink.c
ext/sdl/sdlvideosink.c
ext/voaacenc/gstvoaacenc.c
ext/voamrwbenc/gstvoamrwbenc.c
gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c
gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.c
gst-libs/gst/video/gstbasevideocodec.c
gst-libs/gst/video/gstbasevideodecoder.c
gst-libs/gst/video/gstbasevideoencoder.c
gst/aiff/aiffparse.c
gst/audiovisualizers/gstbaseaudiovisualizer.c
gst/camerabin/gstcamerabin.c
gst/camerabin/gstinputselector.c
gst/camerabin2/gstcamerabin2.c
gst/camerabin2/gstwrappercamerabinsrc.c
gst/cdxaparse/gstcdxaparse.c
gst/coloreffects/gstchromahold.c
gst/dvbsuboverlay/gstdvbsuboverlay.c
gst/dvdspu/gstdvdspu.c
gst/hls/gsthlsdemux.c
gst/liveadder/liveadder.c
gst/mpegdemux/gstmpegdemux.c
gst/mpegpsmux/mpegpsmux.c
gst/mpegtsdemux/mpegtsbase.c
gst/mpegtsdemux/tsdemux.c
gst/mpegtsmux/mpegtsmux.c
gst/mve/gstmvemux.c
gst/mxf/mxfdemux.c
gst/rawparse/gstrawparse.c
gst/sdp/gstsdpdemux.c
gst/tta/gstttaparse.c
gst/videoparsers/gsth264parse.c
gst/videoparsers/gstmpegvideoparse.c
sys/d3dvideosink/d3dvideosink.c
sys/decklink/gstdecklinksink.cpp
sys/decklink/gstdecklinksrc.cpp
sys/dvb/gstdvbsrc.c
sys/shm/gstshmsink.c
tests/examples/scaletempo/Makefile.am
tests/examples/scaletempo/demo-gui.c

Simple merge
Simple merge
@@@ -91,13 -92,16 +91,14 @@@ GST_DEBUG_CATEGORY_STATIC (faad_debug)
  static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
      GST_PAD_SINK,
      GST_PAD_ALWAYS,
-     GST_STATIC_CAPS ("audio/mpeg, " "mpegversion = (int) { 2, 4 }")
+     GST_STATIC_CAPS ("audio/mpeg, " "mpegversion = (int) 2; "
+         "audio/mpeg, mpegversion = (int) 4, stream-format = (string) { raw, adts }")
      );
  
 -#define STATIC_INT_CAPS(bpp) \
 -  "audio/x-raw-int, " \
 -    "endianness = (int) BYTE_ORDER, " \
 -    "signed = (bool) TRUE, " \
 -    "width = (int) " G_STRINGIFY (bpp) ", " \
 -    "depth = (int) " G_STRINGIFY (bpp) ", " \
 +#define STATIC_RAW_CAPS(format) \
 +  "audio/x-raw, " \
 +    "format = (string) "GST_AUDIO_NE(format)", " \
 +    "layout = (string) interleaved, " \
      "rate = (int) [ 8000, 96000 ], " \
      "channels = (int) [ 1, 8 ]"
  
@@@ -921,12 -949,12 +922,13 @@@ gst_kate_enc_chain_text (GstKateEnc * k
  
    if (G_UNLIKELY (ret < 0)) {
      GST_ELEMENT_ERROR (ke, STREAM, ENCODE, (NULL),
-         ("kate_encode_set_markup_type: %d", ret));
+         ("Failed to set markup type: %s",
+             gst_kate_util_get_error_message (ret)));
      rflow = GST_FLOW_ERROR;
    } else {
 -    const char *text = (const char *) GST_BUFFER_DATA (buf);
 -    size_t text_len = GST_BUFFER_SIZE (buf);
 +    const char *text;
 +    size_t text_len;
 +    gboolean need_unmap = TRUE;
      kate_float t0 = start / (double) GST_SECOND;
      kate_float t1 = stop / (double) GST_SECOND;
  
@@@ -180,18 -184,14 +180,19 @@@ gst_kate_parse_push_headers (GstKatePar
  
    headers = parse->streamheader;
    while (headers) {
 +    guint8 *data;
 +    gsize size;
 +
      outbuf = GST_BUFFER_CAST (headers->data);
 -    kate_packet_wrap (&packet, GST_BUFFER_SIZE (outbuf),
 -        GST_BUFFER_DATA (outbuf));
 +
 +    data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_READ);
 +    kate_packet_wrap (&packet, size, data);
      ret = kate_decode_headerin (&parse->ki, &parse->kc, &packet);
      if (G_UNLIKELY (ret < 0)) {
-       GST_WARNING_OBJECT (parse, "kate_decode_headerin returned %d", ret);
+       GST_WARNING_OBJECT (parse, "Failed to decode header: %s",
+           gst_kate_util_get_error_message (ret));
      }
 +    gst_buffer_unmap (outbuf, data, size);
      /* takes ownership of outbuf, which was previously in parse->streamheader */
      outbuf_list = g_list_append (outbuf_list, outbuf);
      headers = headers->next;
Simple merge
@@@ -266,14 -265,12 +269,15 @@@ gst_kate_util_decoder_base_chain_kate_p
      decoder->tags = NULL;
    }
  
 -  kate_packet_wrap (&kp, GST_BUFFER_SIZE (buf), GST_BUFFER_DATA (buf));
 +  data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
 +  kate_packet_wrap (&kp, size, data);
    ret = kate_high_decode_packetin (&decoder->k, &kp, ev);
 +  gst_buffer_unmap (buf, data, size);
 +
    if (G_UNLIKELY (ret < 0)) {
      GST_ELEMENT_ERROR (element, STREAM, DECODE, (NULL),
-         ("Failed to decode Kate packet: %d", ret));
+         ("Failed to decode Kate packet: %s",
+             gst_kate_util_get_error_message (ret)));
      return GST_FLOW_ERROR;
    }
  
Simple merge
Simple merge
@@@ -8,11 -8,9 +8,10 @@@ libgstmpeg2enc_la_SOURCES = 
        gstmpeg2encpicturereader.cc
  
  libgstmpeg2enc_la_CXXFLAGS = \
-         $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) \
-         $(GST_CXXFLAGS) $(MPEG2ENC_CFLAGS)
+       $(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CXXFLAGS) $(MPEG2ENC_CFLAGS)
  libgstmpeg2enc_la_LIBADD = \
 -      $(GST_PLUGINS_BASE_LIBS) $(GST_LIBS) $(MPEG2ENC_LIBS)
 +        $(GST_PLUGINS_BASE_LIBS) -lgstvideo-@GST_MAJORMINOR@ \
 +        $(GST_LIBS) $(MPEG2ENC_LIBS)
  libgstmpeg2enc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
  libgstmpeg2enc_la_LIBTOOLFLAGS = --tag=disable-static
  
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -159,13 -176,7 +159,15 @@@ gst_voaacenc_class_init (GstVoAacEncCla
            0, G_MAXINT, VOAAC_ENC_DEFAULT_BITRATE,
            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
  
 +  gst_element_class_add_pad_template (element_class,
 +      gst_static_pad_template_get (&sink_template));
 +  gst_element_class_add_pad_template (element_class,
 +      gst_static_pad_template_get (&src_template));
 +
 +  gst_element_class_set_details_simple (element_class, "AAC audio encoder",
 +      "Codec/Encoder/Audio", "AAC audio encoder", "Kan Hu <kan.hu@linaro.org>");
++
+   GST_DEBUG_CATEGORY_INIT (gst_voaacenc_debug, "voaacenc", 0, "voaac encoder");
  }
  
  static void
Simple merge
Simple merge
  #ifdef HAVE_CONFIG_H
  #include "config.h"
  #endif
+ /* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
+  * with newer GLib versions (>= 2.31.0) */
+ #define GLIB_DISABLE_DEPRECATION_WARNINGS
  #include <string.h>
 -#include <gst/controller/gstcontroller.h>
  
  #include "gstbaseaudiovisualizer.h"
  
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
  
  #include <string.h>
  #include <gst/base/gsttypefindhelper.h>
+ #include <gst/glib-compat-private.h>
  #include "gsthlsdemux.h"
  
 -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src%d",
 +static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src_%u",
      GST_PAD_SRC,
      GST_PAD_SOMETIMES,
      GST_STATIC_CAPS_ANY);
Simple merge
Simple merge
Simple merge
@@@ -174,9 -184,7 +178,10 @@@ mpegts_base_class_init (MpegTSBaseClas
  
    element_class = GST_ELEMENT_CLASS (klass);
    element_class->change_state = mpegts_base_change_state;
 +  gst_element_class_add_pad_template (element_class,
 +      gst_static_pad_template_get (&sink_template));
 +
    gobject_class = G_OBJECT_CLASS (klass);
    gobject_class->set_property = mpegts_base_set_property;
    gobject_class->get_property = mpegts_base_get_property;
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
  #include "config.h"
  #endif
  
 -#ifdef HAVE_UNISTD_H
 -#include <unistd.h>
 -#endif
 -
 -/* include GLIB for G_OS_WIN32 */
 -#include <glib.h>
 -
 -#ifdef G_OS_WIN32
 -#ifdef _MSC_VER
 -#include <Winsock2.h>
 -#endif
 -/* ws2_32.dll has getaddrinfo and freeaddrinfo on Windows XP and later.
 - *  * minwg32 headers check WINVER before allowing the use of these */
 -#ifndef WINVER
 -#define WINVER 0x0501
 -#endif
 -#include <ws2tcpip.h>
 -#else
 -#include <sys/socket.h>
 -#include <netdb.h>
 -#include <netinet/in.h>
 -#endif
 -
 -#include <stdlib.h>
 -#include <string.h>
 -#include <locale.h>
 -#include <stdio.h>
 -#include <stdarg.h>
+ /* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
+  * with newer GLib versions (>= 2.31.0) */
+ #define GLIB_DISABLE_DEPRECATION_WARNINGS
 +#include "gstsdpdemux.h"
  
  #include <gst/rtp/gstrtppayloads.h>
  #include <gst/sdp/gstsdpmessage.h>
Simple merge
@@@ -627,23 -651,17 +651,24 @@@ gst_h264_parse_check_valid_frame (GstBa
  {
    GstH264Parse *h264parse = GST_H264_PARSE (parse);
    GstBuffer *buffer = frame->buffer;
 +  GstMapInfo map;
    guint8 *data;
 -  guint size;
 -  gint current_off = 0;
 +  gsize size;
 +  guint current_off = 0;
-   gboolean drain;
+   gboolean drain, nonext;
    GstH264NalParser *nalparser = h264parse->nalparser;
    GstH264NalUnit nalu;
+   GstH264ParserResult pres;
  
 +  gst_buffer_map (buffer, &map, GST_MAP_READ);
 +  data = map.data;
 +  size = map.size;
 +
    /* expect at least 3 bytes startcode == sc, and 2 bytes NALU payload */
 -  if (G_UNLIKELY (GST_BUFFER_SIZE (buffer) < 5))
 +  if (G_UNLIKELY (size < 5)) {
 +    gst_buffer_unmap (buffer, &map);
      return FALSE;
 +  }
  
    /* need to configure aggregation */
    if (G_UNLIKELY (h264parse->format == GST_H264_PARSE_FORMAT_NONE))
      GST_LOG_OBJECT (h264parse, "resuming frame parsing");
    }
  
-   drain = FALSE;
-   nalu = h264parse->nalu;
 -  data = GST_BUFFER_DATA (buffer);
 -  size = GST_BUFFER_SIZE (buffer);
 -
+   drain = GST_BASE_PARSE_DRAINING (parse);
+   nonext = FALSE;
    current_off = h264parse->current_off;
+   if (current_off < 0)
+     current_off = 0;
+   g_assert (current_off < size);
+   GST_DEBUG_OBJECT (h264parse, "last parse position %d", current_off);
+   /* check for initial skip */
+   if (h264parse->current_off == -1) {
+     pres =
+         gst_h264_parser_identify_nalu_unchecked (nalparser, data, current_off,
+         size, &nalu);
+     switch (pres) {
+       case GST_H264_PARSER_OK:
+         if (nalu.sc_offset > 0) {
+           *skipsize = nalu.sc_offset;
+           goto skip;
+         }
+         break;
+       case GST_H264_PARSER_NO_NAL:
+         *skipsize = size - 3;
+         goto skip;
+         break;
+       default:
+         g_assert_not_reached ();
+         break;
+     }
+   }
  
-   GST_DEBUG_OBJECT (h264parse, "last parse position %u", current_off);
    while (TRUE) {
-     GstH264ParserResult pres;
-     if (h264parse->packetized)
+     if (h264parse->packetized_chunked)
        pres =
            gst_h264_parser_identify_nalu_unchecked (nalparser, data, current_off,
            size, &nalu);
    }
  
  end:
-   *skipsize = h264parse->nalu.sc_offset;
-   *framesize = nalu.offset + nalu.size - h264parse->nalu.sc_offset;
-   h264parse->current_off = current_off;
+   *framesize = nalu.offset + nalu.size;
 +
 +  gst_buffer_unmap (buffer, &map);
    return TRUE;
  
- parsing_error:
-   GST_DEBUG_OBJECT (h264parse, "error parsing Nal Unit");
  more:
    /* ask for best next available */
    *framesize = G_MAXUINT;
-   if (!h264parse->nalu.size) {
-     /* skip up to initial startcode */
-     *skipsize = h264parse->nalu.sc_offset;
-     /* but mind some stuff will have been skipped */
-     g_assert (current_off >= *skipsize);
-     current_off -= *skipsize;
-     h264parse->nalu.sc_offset = 0;
-   } else {
-     *skipsize = 0;
-   }
+   *skipsize = 0;
  
    /* Restart parsing from here next time */
-   h264parse->current_off = current_off;
+   if (current_off > 0)
+     h264parse->current_off = current_off;
  
 +  /* Fall-through. */
 +out:
 +  gst_buffer_unmap (buffer, &map);
    return FALSE;
  
- invalid:
+ skip:
+   GST_DEBUG_OBJECT (h264parse, "skipping %d", *skipsize);
    gst_h264_parse_reset_frame (h264parse);
 -  return FALSE;
 +  goto out;
  }
  
  /* byte together avc codec data based on collected pps and sps so far */
@@@ -1873,8 -1873,18 +1912,18 @@@ gst_h264_parse_chain (GstPad * pad, Gst
              nalu.data + nalu.offset, nalu.size);
          /* at least this should make sense */
          GST_BUFFER_TIMESTAMP (sub) = GST_BUFFER_TIMESTAMP (buffer);
-         GST_LOG_OBJECT (h264parse, "pushing NAL of size %d", nalu.size);
+         /* transfer flags (e.g. DISCONT) for first fragment */
+         if (nalu.offset <= nl)
+           gst_buffer_copy_metadata (sub, buffer, GST_BUFFER_COPY_FLAGS);
+         /* in reverse playback, baseparse gathers buffers, so we cannot
+          * guarantee a buffer to contain a single whole NALU */
+         h264parse->packetized_chunked =
+             (GST_BASE_PARSE (h264parse)->segment.rate > 0.0);
+         h264parse->packetized_last =
+             (nalu.offset + nalu.size + nl >= GST_BUFFER_SIZE (buffer));
+         GST_LOG_OBJECT (h264parse, "pushing NAL of size %d, last = %d",
+             nalu.size, h264parse->packetized_last);
 -        ret = h264parse->parse_chain (pad, sub);
 +        ret = h264parse->parse_chain (pad, parent, sub);
        } else {
          /* pass-through: no looking for frames (and nal processing),
           * so need to parse to collect data here */
Simple merge
@@@ -495,6 -530,9 +530,9 @@@ gst_d3dvideosink_create_shared_hidden_w
  
    CloseHandle (shared.hidden_window_created_signal);
  
 -     goto failed;
+   if (!shared.d3ddev)
++    goto failed;
    GST_DEBUG ("Successfully created Direct3D hidden window, handle: %p",
        shared.hidden_window_handle);
  
@@@ -1356,7 -1370,8 +1370,8 @@@ gst_d3dvideosink_change_state (GstEleme
  
    switch (transition) {
      case GST_STATE_CHANGE_NULL_TO_READY:
-       gst_d3dvideosink_initialize_direct3d (sink);
+       if (!gst_d3dvideosink_initialize_direct3d (sink))
 -        return GST_STATE_CHANGE_FAILURE; 
++        return GST_STATE_CHANGE_FAILURE;
        break;
      case GST_STATE_CHANGE_READY_TO_PAUSED:
        break;
@@@ -1537,187 -1552,207 +1552,207 @@@ gst_d3dvideosink_stop (GstBaseSink * bs
    return TRUE;
  }
  
- static GstFlowReturn
- gst_d3dvideosink_show_frame (GstVideoSink * vsink, GstBuffer * buffer)
+ static void
+ gst_d3dvideosink_flush_gpu (GstD3DVideoSink * sink)
  {
-   GstD3DVideoSink *sink = GST_D3DVIDEOSINK (vsink);
+   LPDIRECT3DQUERY9 pEventQuery = NULL;
  
-   GST_D3DVIDEOSINK_SHARED_D3D_DEV_LOCK GST_D3DVIDEOSINK_SWAP_CHAIN_LOCK (sink);
-   {
-     HRESULT hr;
-     LPDIRECT3DSURFACE9 backBuffer;
+   IDirect3DDevice9_CreateQuery (sink->d3ddev, D3DQUERYTYPE_EVENT, &pEventQuery);
+   if (pEventQuery) {
+     IDirect3DQuery9_Issue (pEventQuery, D3DISSUE_END);
+     /* Empty the command buffer and wait until the GPU is idle. */
+     while (S_FALSE == IDirect3DQuery9_GetData (pEventQuery, NULL, 0,
+             D3DGETDATA_FLUSH));
+     IDirect3DQuery9_Release (pEventQuery);
+   }
+ }
  
-     if (!shared.d3ddev) {
-       if (!shared.device_lost) {
-         GST_WARNING ("No Direct3D device has been created, stopping");
-         goto error;
-       } else {
-         GST_WARNING
-             ("Direct3D device is lost. Maintaining flow until it has been reset.");
-         goto success;
+ static void
+ gst_d3dvideosink_wait_for_vsync (GstD3DVideoSink * sink)
+ {
+   if (sink->d3dpp.PresentationInterval == D3DPRESENT_INTERVAL_IMMEDIATE) {
+     D3DRASTER_STATUS raster_stat;
+     D3DDISPLAYMODE d3ddm;
+     UINT lastScanline = 0;
+     UINT vblankStart = 0;
+     HANDLE thdl = GetCurrentThread ();
+     int prio = GetThreadPriority (thdl);
+     ZeroMemory (&d3ddm, sizeof (d3ddm));
+     IDirect3DDevice9_GetDisplayMode (sink->d3ddev, 0, &d3ddm);
+     vblankStart = d3ddm.Height - 10;
+     SetThreadPriority (thdl, THREAD_PRIORITY_TIME_CRITICAL);
+     do {
+       if (FAILED (IDirect3DDevice9_GetRasterStatus (sink->d3ddev, 0,
+                   &raster_stat))) {
+         GST_ERROR_OBJECT (sink, "GetRasterStatus failed");
        }
-     }
-     if (!sink->d3d_offscreen_surface) {
-       GST_WARNING ("No Direct3D offscreen surface has been created, stopping");
-       goto error;
-     }
+       break;
+       if (!raster_stat.InVBlank) {
+         if (raster_stat.ScanLine < lastScanline) {
+           GST_INFO_OBJECT (sink, "missed last vsync curr : %d",
+               raster_stat.ScanLine);
+           break;
+         }
+         lastScanline = raster_stat.ScanLine;
+         SwitchToThread ();
+       }
+     } while (raster_stat.ScanLine < vblankStart);
+     SetThreadPriority (thdl, prio);
+   }
+ }
  
-     if (!sink->d3d_swap_chain) {
-       GST_WARNING ("No Direct3D swap chain has been created, stopping");
-       goto error;
-     }
+ static GstFlowReturn
+ gst_d3dvideosink_show_frame (GstVideoSink * vsink, GstBuffer * buffer)
+ {
+   GstD3DVideoSink *sink = GST_D3DVIDEOSINK (vsink);
+   LPDIRECT3DSURFACE9 drawSurface = NULL;
  
-     if (sink->window_closed) {
-       GST_WARNING ("Window has been closed, stopping");
+   GST_D3DVIDEOSINK_SWAP_CHAIN_LOCK (sink);
+   if (!sink->d3ddev) {
+     if (!shared.device_lost) {
+       GST_ERROR_OBJECT (sink, "No Direct3D device has been created, stopping");
        goto error;
+     } else {
+       GST_WARNING_OBJECT (sink,
+           "Direct3D device is lost. Maintaining flow until it has been reset.");
+       goto success;
      }
+   }
  
-     if (sink->window_handle && !sink->is_new_window) {
-       if (shared.d3ddev) {
-         gint win_width = 0, win_height = 0;
-         D3DPRESENT_PARAMETERS d3dpp;
-         ZeroMemory (&d3dpp, sizeof (d3dpp));
-         if (gst_d3dvideosink_window_size (sink, &win_width, &win_height)) {
-           IDirect3DSwapChain9_GetPresentParameters (sink->d3d_swap_chain,
-               &d3dpp);
-           if ((d3dpp.BackBufferWidth > 0 && d3dpp.BackBufferHeight > 0
-                   && win_width != d3dpp.BackBufferWidth)
-               || win_height != d3dpp.BackBufferHeight)
-             gst_d3dvideosink_resize_swap_chain (sink, win_width, win_height);
-         }
-       }
-     }
-     /* Set the render target to our swap chain */
-     IDirect3DSwapChain9_GetBackBuffer (sink->d3d_swap_chain, 0,
-         D3DBACKBUFFER_TYPE_MONO, &backBuffer);
-     IDirect3DDevice9_SetRenderTarget (shared.d3ddev, 0, backBuffer);
-     IDirect3DSurface9_Release (backBuffer);
+   if (sink->window_closed) {
+     GST_ERROR_OBJECT (sink, "Window has been closed, stopping");
+     goto error;
+   }
  
-     /* Clear the target */
-     IDirect3DDevice9_Clear (shared.d3ddev, 0, NULL, D3DCLEAR_TARGET,
-         D3DCOLOR_XRGB (0, 0, 0), 1.0f, 0);
  
-     if (SUCCEEDED (IDirect3DDevice9_BeginScene (shared.d3ddev))) {
-       if (GST_BUFFER_DATA (buffer)) {
-         D3DLOCKED_RECT lr;
-         guint8 *dest, *source;
-         int srcstride, dststride, i;
-         IDirect3DSurface9_LockRect (sink->d3d_offscreen_surface, &lr, NULL, 0);
-         dest = (guint8 *) lr.pBits;
-         source = GST_BUFFER_DATA (buffer);
-         if (dest) {
-           if (gst_video_format_is_yuv (sink->format)) {
-             guint32 fourcc = gst_video_format_to_fourcc (sink->format);
-             switch (fourcc) {
-               case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
-               case GST_MAKE_FOURCC ('Y', 'U', 'Y', 'V'):
-               case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
-                 dststride = lr.Pitch;
-                 srcstride = GST_BUFFER_SIZE (buffer) / sink->height;
-                 for (i = 0; i < sink->height; ++i)
-                   memcpy (dest + dststride * i, source + srcstride * i,
-                       srcstride);
-                 break;
-               case GST_MAKE_FOURCC ('I', '4', '2', '0'):
-               case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
-               {
-                 int srcystride, srcvstride, srcustride;
-                 int dstystride, dstvstride, dstustride;
-                 int rows;
-                 guint8 *srcv, *srcu, *dstv, *dstu;
-                 rows = sink->height;
-                 /* Source y, u and v strides */
-                 srcystride = GST_ROUND_UP_4 (sink->width);
-                 srcustride = GST_ROUND_UP_8 (sink->width) / 2;
-                 srcvstride = GST_ROUND_UP_8 (srcystride) / 2;
-                 /* Destination y, u and v strides */
-                 dstystride = lr.Pitch;
-                 dstustride = dstystride / 2;
-                 dstvstride = dstustride;
-                 srcu = source + srcystride * GST_ROUND_UP_2 (rows);
-                 srcv = srcu + srcustride * GST_ROUND_UP_2 (rows) / 2;
-                 if (fourcc == GST_MAKE_FOURCC ('I', '4', '2', '0')) {
-                   /* swap u and v planes */
-                   dstv = dest + dstystride * rows;
-                   dstu = dstv + dstustride * rows / 2;
-                 } else {
-                   dstu = dest + dstystride * rows;
-                   dstv = dstu + dstustride * rows / 2;
-                 }
+   drawSurface = sink->d3d_offscreen_surface;
+   if (SUCCEEDED (IDirect3DDevice9_BeginScene (sink->d3ddev))) {
+     if (GST_BUFFER_DATA (buffer)) {
+       D3DLOCKED_RECT lr;
+       guint8 *dest, *source;
+       int srcstride, dststride, i;
+       IDirect3DSurface9_LockRect (drawSurface, &lr, NULL, 0);
+       dest = (guint8 *) lr.pBits;
+       source = GST_BUFFER_DATA (buffer);
+       if (dest) {
+         if (gst_video_format_is_yuv (sink->format)) {
+           guint32 fourcc = gst_video_format_to_fourcc (sink->format);
+           switch (fourcc) {
+             case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
+             case GST_MAKE_FOURCC ('Y', 'U', 'Y', 'V'):
+             case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
+               dststride = lr.Pitch;
+               srcstride = GST_BUFFER_SIZE (buffer) / sink->height;
+               for (i = 0; i < sink->height; ++i)
+                 memcpy (dest + dststride * i, source + srcstride * i,
+                     srcstride);
+               break;
+             case GST_MAKE_FOURCC ('I', '4', '2', '0'):
+             case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
+             {
+               int srcystride, srcvstride, srcustride;
+               int dstystride, dstvstride, dstustride;
+               int rows;
+               guint8 *srcv, *srcu, *dstv, *dstu;
+               rows = sink->height;
+               /* Source y, u and v strides */
+               srcystride = GST_ROUND_UP_4 (sink->width);
+               srcustride = GST_ROUND_UP_8 (sink->width) / 2;
+               srcvstride = GST_ROUND_UP_8 (srcystride) / 2;
+               /* Destination y, u and v strides */
+               dstystride = lr.Pitch;
+               dstustride = dstystride / 2;
+               dstvstride = dstustride;
+               srcu = source + srcystride * GST_ROUND_UP_2 (rows);
+               srcv = srcu + srcustride * GST_ROUND_UP_2 (rows) / 2;
+               if (fourcc == GST_MAKE_FOURCC ('I', '4', '2', '0')) {
+                 /* swap u and v planes */
+                 dstv = dest + dstystride * rows;
+                 dstu = dstv + dstustride * rows / 2;
+               } else {
+                 dstu = dest + dstystride * rows;
+                 dstv = dstu + dstustride * rows / 2;
+               }
  
-                 for (i = 0; i < rows; ++i) {
-                   /* Copy the y plane */
-                   memcpy (dest + dstystride * i, source + srcystride * i,
-                       srcystride);
-                 }
+               for (i = 0; i < rows; ++i) {
+                 /* Copy the y plane */
+                 memcpy (dest + dstystride * i, source + srcystride * i,
+                     srcystride);
+               }
  
-                 for (i = 0; i < rows / 2; ++i) {
-                   /* Copy the u plane */
-                   memcpy (dstu + dstustride * i, srcu + srcustride * i,
-                       srcustride);
-                   /* Copy the v plane */
-                   memcpy (dstv + dstvstride * i, srcv + srcvstride * i,
-                       srcvstride);
+               for (i = 0; i < rows / 2; ++i) {
+                 /* Copy the u plane */
+                 memcpy (dstu + dstustride * i, srcu + srcustride * i,
+                     srcustride);
+                 /* Copy the v plane */
+                 memcpy (dstv + dstvstride * i, srcv + srcvstride * i,
+                     srcvstride);
+               }
+               break;
+             }
+             case GST_MAKE_FOURCC ('N', 'V', '1', '2'):
+             {
+               guint8 *dst = dest;
+               int component;
+               dststride = lr.Pitch;
+               for (component = 0; component < 2; component++) {
+                 const int compHeight =
+                     gst_video_format_get_component_height (sink->format,
+                     component, sink->height);
+                 guint8 *src =
+                     source +
+                     gst_video_format_get_component_offset (sink->format,
+                     component, sink->width, sink->height);
+                 srcstride =
+                     gst_video_format_get_row_stride (sink->format, component,
+                     sink->width);
+                 for (i = 0; i < compHeight; i++) {
+                   memcpy (dst + dststride * i, src + srcstride * i, srcstride);
                  }
-                 break;
+                 dst += dststride * compHeight;
                }
-               default:
-                 g_assert_not_reached ();
+               break;
              }
-           } else if (gst_video_format_is_rgb (sink->format)) {
-             dststride = lr.Pitch;
-             srcstride = GST_BUFFER_SIZE (buffer) / sink->height;
-             for (i = 0; i < sink->height; ++i)
-               memcpy (dest + dststride * i, source + srcstride * i, srcstride);
+             default:
+               g_assert_not_reached ();
            }
+         } else if (gst_video_format_is_rgb (sink->format)) {
+           dststride = lr.Pitch;
+           srcstride = GST_BUFFER_SIZE (buffer) / sink->height;
+           for (i = 0; i < sink->height; ++i)
+             memcpy (dest + dststride * i, source + srcstride * i, srcstride);
          }
-         IDirect3DSurface9_UnlockRect (sink->d3d_offscreen_surface);
-       }
-       gst_d3dvideosink_stretch (sink, backBuffer);
-       IDirect3DDevice9_EndScene (shared.d3ddev);
-     }
-     /* Swap back and front buffers on video card and present to the user */
-     if (FAILED (hr =
-             IDirect3DSwapChain9_Present (sink->d3d_swap_chain, NULL, NULL, NULL,
-                 NULL, 0))) {
-       switch (hr) {
-         case D3DERR_DEVICELOST:
-         case D3DERR_DEVICENOTRESET:
-           gst_d3dvideosink_notify_device_lost (sink);
-           break;
-         default:
-           goto wrong_state;
        }
+       IDirect3DSurface9_UnlockRect (drawSurface);
      }
+     IDirect3DDevice9_EndScene (sink->d3ddev);
    }
  success:
    GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK (sink);
-   GST_D3DVIDEOSINK_SHARED_D3D_DEV_UNLOCK return GST_FLOW_OK;
+   gst_d3dvideosink_refresh (sink);
+   return GST_FLOW_OK;
+ #if 0
  wrong_state:
    GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK (sink);
-   GST_D3DVIDEOSINK_SHARED_D3D_DEV_UNLOCK return GST_FLOW_FLUSHING;
 -  return GST_FLOW_WRONG_STATE;
++  return GST_FLOW_FLUSHING;
  /*unexpected:*/
  /*  GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK(sink); */
- /*  GST_D3DVIDEOSINK_SHARED_D3D_DEV_UNLOCK    */
+ /*      */
  /*  return GST_FLOW_UNEXPECTED;               */
+ #endif
  error:
    GST_D3DVIDEOSINK_SWAP_CHAIN_UNLOCK (sink);
-   GST_D3DVIDEOSINK_SHARED_D3D_DEV_UNLOCK return GST_FLOW_ERROR;
+   return GST_FLOW_ERROR;
  }
  
  /* Simply redraws the last item on our offscreen surface to the window */
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -1,11 -1,8 +1,11 @@@
  noinst_PROGRAMS = scaletempo-demo
  
 +# FIXME 0.11: ignore GValueArray warnings for now until this is sorted
 +ERROR_CFLAGS=
 +
  scaletempo_demo_SOURCES = demo-main.c demo-player.c demo-gui.c
- scaletempo_demo_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GTK_CFLAGS) 
- scaletempo_demo_LDFLAGS = $(GST_LIBS) $(GST_PLUGINS_BASE_LIBS) $(GTK_LIBS) -lgstinterfaces-@GST_MAJORMINOR@
+ scaletempo_demo_CFLAGS = $(GST_PLUGINS_BAD_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(GTK_CFLAGS)
+ scaletempo_demo_LDFLAGS = $(GST_PLUGINS_BASE_LIBS) -lgstinterfaces-@GST_MAJORMINOR@ $(GST_LIBS) $(GTK_LIBS)
  
  noinst_HEADERS = demo-player.h demo-gui.h
  
Simple merge