xorg_xv.c revision 4236493899b9ccfcc8df3dcf81697776621fa1f8
1#include "xorg_tracker.h"
2
3#include <xf86xv.h>
4#include <X11/extensions/Xv.h>
5#include <fourcc.h>
6
7#include "xorg_exa.h"
8#include "xorg_renderer.h"
9#include "xorg_exa_tgsi.h"
10
11#include "cso_cache/cso_context.h"
12
13#include "pipe/p_screen.h"
14#include "pipe/p_inlines.h"
15
16/*XXX get these from pipe's texture limits */
17#define IMAGE_MAX_WIDTH		2048
18#define IMAGE_MAX_HEIGHT	2048
19
20#define RES_720P_X 1280
21#define RES_720P_Y 720
22
23
24/* The ITU-R BT.601 conversion matrix for SDTV. */
25/* original, matrix, but we transpose it to
26 * make the shader easier
27static const float bt_601[] = {
28    1.0, 0.0, 1.4075,   ,
29    1.0, -0.3455, -0.7169, 0,
30    1.0, 1.7790, 0., 0,
31};*/
32static const float bt_601[] = {
33    1.0, 1.0, 1.0,        0.5,
34    0.0, -0.3455, 1.7790, 0,
35    1.4075, -0.7169, 0.,  0,
36};
37
38/* The ITU-R BT.709 conversion matrix for HDTV. */
39/* original, but we transpose to make the conversion
40 * in the shader easier
41static const float bt_709[] = {
42    1.0, 0.0, 1.581, 0,
43    1.0, -0.1881, -0.47, 0,
44    1.0, 1.8629, 0., 0,
45};*/
46static const float bt_709[] = {
47    1.0,   1.0,     1.0,     0.5,
48    0.0,  -0.1881,  1.8629,  0,
49    1.581,-0.47   , 0.0,     0,
50};
51
52#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
53
54static Atom xvBrightness, xvContrast;
55
56#define NUM_TEXTURED_ATTRIBUTES 2
57static XF86AttributeRec TexturedAttributes[NUM_TEXTURED_ATTRIBUTES] = {
58   {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"},
59   {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"}
60};
61
62#define NUM_FORMATS 3
63static XF86VideoFormatRec Formats[NUM_FORMATS] = {
64   {15, TrueColor}, {16, TrueColor}, {24, TrueColor}
65};
66
67static XF86VideoEncodingRec DummyEncoding[1] = {
68   {
69      0,
70      "XV_IMAGE",
71      IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT,
72      {1, 1}
73   }
74};
75
76#define NUM_IMAGES 2
77static XF86ImageRec Images[NUM_IMAGES] = {
78   XVIMAGE_UYVY,
79   XVIMAGE_YUY2,
80};
81
82struct xorg_xv_port_priv {
83   struct xorg_renderer *r;
84
85   RegionRec clip;
86
87   int brightness;
88   int contrast;
89
90   int current_set;
91   /* juggle two sets of seperate Y, U and V
92    * textures */
93   struct pipe_texture *yuv[2][3];
94};
95
96
97static void
98stop_video(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
99{
100   struct xorg_xv_port_priv *priv = (struct xorg_xv_port_priv *)data;
101
102   REGION_EMPTY(pScrn->pScreen, &priv->clip);
103}
104
105static int
106set_port_attribute(ScrnInfoPtr pScrn,
107                   Atom attribute, INT32 value, pointer data)
108{
109   struct xorg_xv_port_priv *priv = (struct xorg_xv_port_priv *)data;
110
111   if (attribute == xvBrightness) {
112      if ((value < -128) || (value > 127))
113         return BadValue;
114      priv->brightness = value;
115   } else if (attribute == xvContrast) {
116      if ((value < 0) || (value > 255))
117         return BadValue;
118      priv->contrast = value;
119   } else
120      return BadMatch;
121
122   return Success;
123}
124
125static int
126get_port_attribute(ScrnInfoPtr pScrn,
127                   Atom attribute, INT32 * value, pointer data)
128{
129   struct xorg_xv_port_priv *priv = (struct xorg_xv_port_priv *)data;
130
131   if (attribute == xvBrightness)
132      *value = priv->brightness;
133   else if (attribute == xvContrast)
134      *value = priv->contrast;
135   else
136      return BadMatch;
137
138   return Success;
139}
140
141static void
142query_best_size(ScrnInfoPtr pScrn,
143                Bool motion,
144                short vid_w, short vid_h,
145                short drw_w, short drw_h,
146                unsigned int *p_w, unsigned int *p_h, pointer data)
147{
148   if (vid_w > (drw_w << 1))
149      drw_w = vid_w >> 1;
150   if (vid_h > (drw_h << 1))
151      drw_h = vid_h >> 1;
152
153   *p_w = drw_w;
154   *p_h = drw_h;
155}
156
157static INLINE struct pipe_texture *
158create_component_texture(struct pipe_context *pipe,
159                         int width, int height)
160{
161   struct pipe_screen *screen = pipe->screen;
162   struct pipe_texture *tex = 0;
163   struct pipe_texture templ;
164
165   memset(&templ, 0, sizeof(templ));
166   templ.target = PIPE_TEXTURE_2D;
167   templ.format = PIPE_FORMAT_L8_UNORM;
168   templ.last_level = 0;
169   templ.width[0] = width;
170   templ.height[0] = height;
171   templ.depth[0] = 1;
172   pf_get_block(PIPE_FORMAT_L8_UNORM, &templ.block);
173   templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
174
175   tex = screen->texture_create(screen, &templ);
176
177   return tex;
178}
179
180static int
181check_yuv_textures(struct xorg_xv_port_priv *priv,  int width, int height)
182{
183   struct pipe_texture **dst = priv->yuv[priv->current_set];
184   if (!dst[0] ||
185       dst[0]->width[0] != width ||
186       dst[0]->height[0] != height) {
187      pipe_texture_reference(&dst[0], NULL);
188   }
189   if (!dst[1] ||
190       dst[1]->width[0] != width ||
191       dst[1]->height[0] != height) {
192      pipe_texture_reference(&dst[1], NULL);
193   }
194   if (!dst[2] ||
195       dst[2]->width[0] != width ||
196       dst[2]->height[0] != height) {
197      pipe_texture_reference(&dst[2], NULL);
198   }
199
200   if (!dst[0])
201      dst[0] = create_component_texture(priv->r->pipe, width, height);
202
203   if (!dst[1])
204      dst[1] = create_component_texture(priv->r->pipe, width, height);
205
206   if (!dst[2])
207      dst[2] = create_component_texture(priv->r->pipe, width, height);
208
209   if (!dst[0] || !dst[1] || !dst[2])
210      return BadAlloc;
211
212   return Success;
213}
214
215static void
216copy_packed_data(ScrnInfoPtr pScrn,
217                 struct xorg_xv_port_priv *port,
218                 int id,
219                 unsigned char *buf,
220                 int srcPitch,
221                 int left,
222                 int top,
223                 int w, int h)
224{
225   unsigned char *src;
226   int i, j;
227   struct pipe_texture **dst = port->yuv[port->current_set];
228   struct pipe_transfer *ytrans, *utrans, *vtrans;
229   struct pipe_screen *screen = port->r->pipe->screen;
230   char *ymap, *vmap, *umap;
231   unsigned char y1, y2, u, v;
232   int yidx, uidx, vidx;
233   int y_array_size = w * h;
234
235   src = buf + (top * srcPitch) + (left << 1);
236
237   ytrans = screen->get_tex_transfer(screen, dst[0],
238                                     0, 0, 0,
239                                     PIPE_TRANSFER_WRITE,
240                                     left, top, w, h);
241   utrans = screen->get_tex_transfer(screen, dst[1],
242                                     0, 0, 0,
243                                     PIPE_TRANSFER_WRITE,
244                                     left, top, w, h);
245   vtrans = screen->get_tex_transfer(screen, dst[2],
246                                     0, 0, 0,
247                                     PIPE_TRANSFER_WRITE,
248                                     left, top, w, h);
249
250   ymap = (char*)screen->transfer_map(screen, ytrans);
251   umap = (char*)screen->transfer_map(screen, utrans);
252   vmap = (char*)screen->transfer_map(screen, vtrans);
253
254   yidx = uidx = vidx = 0;
255
256   switch (id) {
257   case FOURCC_YV12: {
258      for (i = 0; i < w; ++i) {
259         for (j = 0; j < h; ++j) {
260            /*XXX use src? */
261            y1  = buf[j*w + i];
262            u   = buf[(j/2) * (w/2) + i/2 + y_array_size];
263            v   = buf[(j/2) * (w/2) + i/2 + y_array_size + y_array_size/4];
264            ymap[yidx++] = y1;
265            umap[uidx++] = u;
266            vmap[vidx++] = v;
267         }
268      }
269   }
270      break;
271   case FOURCC_UYVY:
272      for (i = 0; i < y_array_size; i +=2 ) {
273         /* extracting two pixels */
274         u  = buf[0];
275         y1 = buf[1];
276         v  = buf[2];
277         y2 = buf[3];
278         buf += 4;
279
280         ymap[yidx++] = y1;
281         ymap[yidx++] = y2;
282         umap[uidx++] = u;
283         umap[uidx++] = u;
284         vmap[vidx++] = v;
285         vmap[vidx++] = v;
286      }
287      break;
288   case FOURCC_YUY2:
289      for (i = 0; i < y_array_size; i +=2 ) {
290         /* extracting two pixels */
291         y1 = buf[0];
292         u  = buf[1];
293         y2 = buf[2];
294         v  = buf[3];
295
296         buf += 4;
297
298         ymap[yidx++] = y1;
299         ymap[yidx++] = y2;
300         umap[uidx++] = u;
301         umap[uidx++] = u;
302         vmap[vidx++] = v;
303         vmap[vidx++] = v;
304      }
305      break;
306   default:
307      debug_assert(!"Unsupported yuv format!");
308      break;
309   }
310
311   screen->transfer_unmap(screen, ytrans);
312   screen->transfer_unmap(screen, utrans);
313   screen->transfer_unmap(screen, vtrans);
314   screen->tex_transfer_destroy(ytrans);
315   screen->tex_transfer_destroy(utrans);
316   screen->tex_transfer_destroy(vtrans);
317}
318
319
320static void
321setup_fs_video_constants(struct xorg_renderer *r, boolean hdtv)
322{
323   const int param_bytes = 12 * sizeof(float);
324   const float *video_constants = (hdtv) ? bt_709 : bt_601;
325
326   renderer_set_constants(r, PIPE_SHADER_FRAGMENT,
327                          video_constants, param_bytes);
328}
329
330static void
331draw_yuv(struct xorg_xv_port_priv *port,
332         int src_x, int src_y, int src_w, int src_h,
333         int dst_x, int dst_y, int dst_w, int dst_h)
334{
335   struct pipe_texture **textures = port->yuv[port->current_set];
336
337   renderer_draw_yuv(port->r,
338                     src_x, src_y, src_w, src_h,
339                     dst_x, dst_y, dst_w, dst_h,
340                     textures);
341}
342
343static void
344bind_blend_state(struct xorg_xv_port_priv *port)
345{
346   struct pipe_blend_state blend;
347
348   memset(&blend, 0, sizeof(struct pipe_blend_state));
349   blend.blend_enable = 1;
350   blend.colormask |= PIPE_MASK_RGBA;
351
352   /* porter&duff src */
353   blend.rgb_src_factor   = PIPE_BLENDFACTOR_ONE;
354   blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
355   blend.rgb_dst_factor   = PIPE_BLENDFACTOR_ZERO;
356   blend.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
357
358   cso_set_blend(port->r->cso, &blend);
359}
360
361
362static void
363bind_shaders(struct xorg_xv_port_priv *port)
364{
365   unsigned vs_traits = 0, fs_traits = 0;
366   struct xorg_shader shader;
367
368   vs_traits |= VS_YUV;
369   fs_traits |= FS_YUV;
370
371   shader = xorg_shaders_get(port->r->shaders, vs_traits, fs_traits);
372   cso_set_vertex_shader_handle(port->r->cso, shader.vs);
373   cso_set_fragment_shader_handle(port->r->cso, shader.fs);
374}
375
376static INLINE void
377conditional_flush(struct pipe_context *pipe, struct pipe_texture **tex,
378                  int num)
379{
380   int i;
381   for (i = 0; i < num; ++i) {
382      if (tex[i] && pipe->is_texture_referenced(pipe, tex[i], 0, 0) &
383          PIPE_REFERENCED_FOR_WRITE) {
384         pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
385         return;
386      }
387   }
388}
389
390static void
391bind_samplers(struct xorg_xv_port_priv *port)
392{
393   struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
394   struct pipe_sampler_state sampler;
395   struct pipe_texture **dst = port->yuv[port->current_set];
396
397   memset(&sampler, 0, sizeof(struct pipe_sampler_state));
398
399   conditional_flush(port->r->pipe, dst, 3);
400
401   sampler.wrap_s = PIPE_TEX_WRAP_CLAMP;
402   sampler.wrap_t = PIPE_TEX_WRAP_CLAMP;
403   sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR;
404   sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR;
405   sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST;
406   sampler.normalized_coords = 1;
407
408   samplers[0] = &sampler;
409   samplers[1] = &sampler;
410   samplers[2] = &sampler;
411
412
413   cso_set_samplers(port->r->cso, 3,
414                    (const struct pipe_sampler_state **)samplers);
415   cso_set_sampler_textures(port->r->cso, 3,
416                            dst);
417}
418
419static int
420display_video(ScrnInfoPtr pScrn, struct xorg_xv_port_priv *pPriv, int id,
421              RegionPtr dstRegion,
422              int src_x, int src_y, int src_w, int src_h,
423              int dstX, int dstY, int dst_w, int dst_h,
424              PixmapPtr pPixmap)
425{
426   modesettingPtr ms = modesettingPTR(pScrn);
427   BoxPtr pbox;
428   int nbox;
429   int dxo, dyo;
430   Bool hdtv;
431   int x, y, w, h;
432   struct exa_pixmap_priv *dst = exaGetPixmapDriverPrivate(pPixmap);
433   struct pipe_surface *dst_surf = xorg_gpu_surface(pPriv->r->pipe->screen, dst);
434
435   if (dst && !dst->tex) {
436	xorg_exa_set_shared_usage(pPixmap);
437	pScrn->pScreen->ModifyPixmapHeader(pPixmap, 0, 0, 0, 0, 0, NULL);
438   }
439
440   if (!dst || !dst->tex)
441      XORG_FALLBACK("Xv destination %s", !dst ? "!dst" : "!dst->tex");
442
443   hdtv = ((src_w >= RES_720P_X) && (src_h >= RES_720P_Y));
444
445   REGION_TRANSLATE(pScrn->pScreen, dstRegion, -pPixmap->screen_x,
446                    -pPixmap->screen_y);
447
448   dxo = dstRegion->extents.x1;
449   dyo = dstRegion->extents.y1;
450
451   pbox = REGION_RECTS(dstRegion);
452   nbox = REGION_NUM_RECTS(dstRegion);
453
454   renderer_bind_destination(pPriv->r, dst_surf,
455                             dst_surf->width, dst_surf->height);
456
457   bind_blend_state(pPriv);
458   bind_shaders(pPriv);
459   bind_samplers(pPriv);
460   setup_fs_video_constants(pPriv->r, hdtv);
461
462   exaMoveInPixmap(pPixmap);
463   DamageDamageRegion(&pPixmap->drawable, dstRegion);
464
465   while (nbox--) {
466      int box_x1 = pbox->x1;
467      int box_y1 = pbox->y1;
468      int box_x2 = pbox->x2;
469      int box_y2 = pbox->y2;
470      float diff_x = (float)src_w / (float)dst_w;
471      float diff_y = (float)src_h / (float)dst_h;
472      int offset_x = box_x1 - dstX + pPixmap->screen_x;
473      int offset_y = box_y1 - dstY + pPixmap->screen_y;
474      int offset_w;
475      int offset_h;
476
477      x = box_x1;
478      y = box_y1;
479      w = box_x2 - box_x1;
480      h = box_y2 - box_y1;
481
482      offset_w = dst_w - w;
483      offset_h = dst_h - h;
484
485      draw_yuv(pPriv, src_x + offset_x*diff_x, src_y + offset_y*diff_y,
486               src_w - offset_w*diff_x, src_h - offset_h*diff_x,
487               x, y, w, h);
488
489      pbox++;
490   }
491   DamageRegionProcessPending(&pPixmap->drawable);
492
493   pipe_surface_reference(&dst_surf, NULL);
494
495   return TRUE;
496}
497
498static int
499put_image(ScrnInfoPtr pScrn,
500          short src_x, short src_y,
501          short drw_x, short drw_y,
502          short src_w, short src_h,
503          short drw_w, short drw_h,
504          int id, unsigned char *buf,
505          short width, short height,
506          Bool sync, RegionPtr clipBoxes, pointer data,
507          DrawablePtr pDraw)
508{
509   struct xorg_xv_port_priv *pPriv = (struct xorg_xv_port_priv *) data;
510   ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
511   PixmapPtr pPixmap;
512   INT32 x1, x2, y1, y2;
513   int srcPitch;
514   BoxRec dstBox;
515   int ret;
516
517   /* Clip */
518   x1 = src_x;
519   x2 = src_x + src_w;
520   y1 = src_y;
521   y2 = src_y + src_h;
522
523   dstBox.x1 = drw_x;
524   dstBox.x2 = drw_x + drw_w;
525   dstBox.y1 = drw_y;
526   dstBox.y2 = drw_y + drw_h;
527
528   if (!xf86XVClipVideoHelper(&dstBox, &x1, &x2, &y1, &y2, clipBoxes,
529			      width, height))
530      return Success;
531
532   switch (id) {
533   case FOURCC_UYVY:
534   case FOURCC_YUY2:
535   default:
536      srcPitch = width << 1;
537      break;
538   }
539
540   ret = check_yuv_textures(pPriv, width, height);
541
542   if (ret)
543      return ret;
544
545   copy_packed_data(pScrn, pPriv, id, buf, srcPitch,
546                    src_x, src_y, width, height);
547
548   if (pDraw->type == DRAWABLE_WINDOW) {
549      pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr)pDraw);
550   } else {
551      pPixmap = (PixmapPtr)pDraw;
552   }
553
554   display_video(pScrn, pPriv, id, clipBoxes,
555                 src_x, src_y, src_w, src_h,
556                 drw_x, drw_y,
557                 drw_w, drw_h, pPixmap);
558
559   pPriv->current_set = (pPriv->current_set + 1) & 1;
560   return Success;
561}
562
563static int
564query_image_attributes(ScrnInfoPtr pScrn,
565                       int id,
566                       unsigned short *w, unsigned short *h,
567                       int *pitches, int *offsets)
568{
569   int size;
570
571   if (*w > IMAGE_MAX_WIDTH)
572      *w = IMAGE_MAX_WIDTH;
573   if (*h > IMAGE_MAX_HEIGHT)
574      *h = IMAGE_MAX_HEIGHT;
575
576   *w = (*w + 1) & ~1;
577   if (offsets)
578      offsets[0] = 0;
579
580   switch (id) {
581   case FOURCC_UYVY:
582   case FOURCC_YUY2:
583   default:
584      size = *w << 1;
585      if (pitches)
586	 pitches[0] = size;
587      size *= *h;
588      break;
589   }
590
591   return size;
592}
593
594static struct xorg_xv_port_priv *
595port_priv_create(struct xorg_renderer *r)
596{
597   struct xorg_xv_port_priv *priv = NULL;
598
599   priv = calloc(1, sizeof(struct xorg_xv_port_priv));
600
601   if (!priv)
602      return NULL;
603
604   priv->r = r;
605
606   REGION_NULL(pScreen, &priv->clip);
607
608   debug_assert(priv && priv->r);
609
610   return priv;
611}
612
613static XF86VideoAdaptorPtr
614xorg_setup_textured_adapter(ScreenPtr pScreen)
615{
616   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
617   modesettingPtr ms = modesettingPTR(pScrn);
618   XF86VideoAdaptorPtr adapt;
619   XF86AttributePtr attrs;
620   DevUnion *dev_unions;
621   int nports = 16, i;
622   int nattributes;
623
624   nattributes = NUM_TEXTURED_ATTRIBUTES;
625
626   debug_assert(ms->exa);
627   debug_assert(ms->exa->renderer);
628
629   adapt = calloc(1, sizeof(XF86VideoAdaptorRec));
630   dev_unions = calloc(nports, sizeof(DevUnion));
631   attrs = calloc(nattributes, sizeof(XF86AttributeRec));
632   if (adapt == NULL || dev_unions == NULL || attrs == NULL) {
633      free(adapt);
634      free(dev_unions);
635      free(attrs);
636      return NULL;
637   }
638
639   adapt->type = XvWindowMask | XvInputMask | XvImageMask;
640   adapt->flags = 0;
641   adapt->name = "Gallium3D Textured Video";
642   adapt->nEncodings = 1;
643   adapt->pEncodings = DummyEncoding;
644   adapt->nFormats = NUM_FORMATS;
645   adapt->pFormats = Formats;
646   adapt->nPorts = 0;
647   adapt->pPortPrivates = dev_unions;
648   adapt->nAttributes = nattributes;
649   adapt->pAttributes = attrs;
650   memcpy(attrs, TexturedAttributes, nattributes * sizeof(XF86AttributeRec));
651   adapt->nImages = NUM_IMAGES;
652   adapt->pImages = Images;
653   adapt->PutVideo = NULL;
654   adapt->PutStill = NULL;
655   adapt->GetVideo = NULL;
656   adapt->GetStill = NULL;
657   adapt->StopVideo = stop_video;
658   adapt->SetPortAttribute = set_port_attribute;
659   adapt->GetPortAttribute = get_port_attribute;
660   adapt->QueryBestSize = query_best_size;
661   adapt->PutImage = put_image;
662   adapt->QueryImageAttributes = query_image_attributes;
663
664   for (i = 0; i < nports; i++) {
665      struct xorg_xv_port_priv *priv =
666         port_priv_create(ms->exa->renderer);
667
668      adapt->pPortPrivates[i].ptr = (pointer) (priv);
669      adapt->nPorts++;
670   }
671
672   return adapt;
673}
674
675void
676xorg_xv_init(ScreenPtr pScreen)
677{
678   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
679   /*modesettingPtr ms = modesettingPTR(pScrn);*/
680   XF86VideoAdaptorPtr *adaptors, *new_adaptors = NULL;
681   XF86VideoAdaptorPtr textured_adapter;
682   int num_adaptors;
683
684   num_adaptors = xf86XVListGenericAdaptors(pScrn, &adaptors);
685   new_adaptors = malloc((num_adaptors + 1) * sizeof(XF86VideoAdaptorPtr *));
686   if (new_adaptors == NULL)
687      return;
688
689   memcpy(new_adaptors, adaptors, num_adaptors * sizeof(XF86VideoAdaptorPtr));
690   adaptors = new_adaptors;
691
692   /* Add the adaptors supported by our hardware.  First, set up the atoms
693    * that will be used by both output adaptors.
694    */
695   xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
696   xvContrast = MAKE_ATOM("XV_CONTRAST");
697
698   textured_adapter = xorg_setup_textured_adapter(pScreen);
699
700   debug_assert(textured_adapter);
701
702   if (textured_adapter) {
703      adaptors[num_adaptors++] = textured_adapter;
704   }
705
706   if (num_adaptors) {
707      xf86XVScreenInit(pScreen, adaptors, num_adaptors);
708   } else {
709      xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
710                 "Disabling Xv because no adaptors could be initialized.\n");
711   }
712
713   free(adaptors);
714}
715