1848b8605Smrg/**************************************************************************
2848b8605Smrg *
3848b8605Smrg * Copyright 2009 Younes Manton.
4848b8605Smrg * All Rights Reserved.
5848b8605Smrg *
6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7848b8605Smrg * copy of this software and associated documentation files (the
8848b8605Smrg * "Software"), to deal in the Software without restriction, including
9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish,
10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to
11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to
12848b8605Smrg * the following conditions:
13848b8605Smrg *
14848b8605Smrg * The above copyright notice and this permission notice (including the
15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions
16848b8605Smrg * of the Software.
17848b8605Smrg *
18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25848b8605Smrg *
26848b8605Smrg **************************************************************************/
27848b8605Smrg
28848b8605Smrg#include "pipe/p_video_codec.h"
29848b8605Smrg
30848b8605Smrg#include "util/u_video.h"
31848b8605Smrg
32848b8605Smrg#include "vl_decoder.h"
33848b8605Smrg#include "vl_mpeg12_decoder.h"
34848b8605Smrg
35848b8605Smrgbool
36848b8605Smrgvl_profile_supported(struct pipe_screen *screen, enum pipe_video_profile profile,
37848b8605Smrg                     enum pipe_video_entrypoint entrypoint)
38848b8605Smrg{
39848b8605Smrg   assert(screen);
40848b8605Smrg   switch (u_reduce_video_profile(profile)) {
41848b8605Smrg      case PIPE_VIDEO_FORMAT_MPEG12:
42848b8605Smrg         return entrypoint != PIPE_VIDEO_ENTRYPOINT_ENCODE;
43848b8605Smrg      default:
44848b8605Smrg         return false;
45848b8605Smrg   }
46848b8605Smrg}
47848b8605Smrg
48848b8605Smrgint
49848b8605Smrgvl_level_supported(struct pipe_screen *screen, enum pipe_video_profile profile)
50848b8605Smrg{
51848b8605Smrg   assert(screen);
52848b8605Smrg   switch (profile) {
53848b8605Smrg      case PIPE_VIDEO_PROFILE_MPEG1:
54848b8605Smrg         return 0;
55848b8605Smrg      case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
56848b8605Smrg      case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
57848b8605Smrg         return 3;
58848b8605Smrg      default:
59848b8605Smrg         return 0;
60848b8605Smrg   }
61848b8605Smrg}
62848b8605Smrg
63848b8605Smrgstruct pipe_video_codec *
64848b8605Smrgvl_create_decoder(struct pipe_context *pipe,
65848b8605Smrg                  const struct pipe_video_codec *templat)
66848b8605Smrg{
67848b8605Smrg   unsigned width = templat->width, height = templat->height;
68848b8605Smrg   struct pipe_video_codec temp;
69848b8605Smrg   bool pot_buffers;
70848b8605Smrg
71848b8605Smrg   assert(pipe);
72848b8605Smrg   assert(width > 0 && height > 0);
73848b8605Smrg
74848b8605Smrg   pot_buffers = !pipe->screen->get_video_param
75848b8605Smrg   (
76848b8605Smrg      pipe->screen,
77848b8605Smrg      templat->profile,
78848b8605Smrg      templat->entrypoint,
79848b8605Smrg      PIPE_VIDEO_CAP_NPOT_TEXTURES
80848b8605Smrg   );
81848b8605Smrg
82848b8605Smrg   temp = *templat;
83848b8605Smrg   temp.width = pot_buffers ? util_next_power_of_two(width) : align(width, VL_MACROBLOCK_WIDTH);
84848b8605Smrg   temp.height = pot_buffers ? util_next_power_of_two(height) : align(height, VL_MACROBLOCK_HEIGHT);
85848b8605Smrg
86848b8605Smrg   switch (u_reduce_video_profile(temp.profile)) {
87848b8605Smrg      case PIPE_VIDEO_FORMAT_MPEG12:
88848b8605Smrg         return vl_create_mpeg12_decoder(pipe, &temp);
89848b8605Smrg
90848b8605Smrg      default:
91848b8605Smrg         return NULL;
92848b8605Smrg   }
93848b8605Smrg   return NULL;
94848b8605Smrg}
95