summaryrefslogtreecommitdiff
path: root/src/libspudec/xine_decoder.c
blob: 8f9acdeb6edd39846e9b2848d88df5db266a3296 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* 
 * Copyright (C) 2000-2001 the xine project
 * 
 * Copyright (C) James Courtier-Dutton James@superbug.demon.co.uk - July 2001
 *
 * This file is part of xine, a unix video player.
 * 
 * xine is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * xine 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
 *
 * $Id: xine_decoder.c,v 1.2 2001/07/04 20:32:29 uid32519 Exp $
 *
 * stuff needed to turn libspu into a xine decoder plugin
 */

/*
 * FIXME: libspu uses global variables (that are written to)
 */


#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "spu.h"
#include "buffer.h"
#include "xine_internal.h"

#define FRAME_SIZE 4096


typedef struct spudec_decoder_s {
  spu_decoder_t    spu_decoder;

  uint32_t         pts;

  uint8_t          frame_buffer[FRAME_SIZE];
  uint8_t         *frame_ptr;
  int              sync_todo;
  int              frame_length, frame_todo;
  uint16_t         syncword;

  vo_instance_t   *vo_out;
  vo_overlay_t    *spu;
  int              spu_caps;
  int              bypass_mode;
  int              max_num_channels;
  int              output_sampling_rate;
  int              output_open;
  int              output_mode;

} spudec_decoder_t;

int spudec_can_handle (spu_decoder_t *this_gen, int buf_type) {
  return ((buf_type & 0xFFFF0000) == BUF_SPU_PACKAGE) ;
}


void spudec_init (spu_decoder_t *this_gen, vo_instance_t *vo_out) {

  spudec_decoder_t *this = (spudec_decoder_t *) this_gen;
  printf("spudec_init %p\n",&vo_out);
  this->vo_out      = vo_out;
  this->spu_caps    = vo_out->get_capabilities(vo_out);
  this->syncword    = 0;
  this->sync_todo   = 6;
  this->output_open = 0;

//  spu_init ();

}

/* overlay_txt is just for test purposes */
u_int *overlay_txt (vo_overlay_t *spu, float o1)
{
  u_int x, y;
  u_char tmp;
  /*        u_char *clr_ptr1 = (u_char *) img1; */
  u_char *clr_ptr2;
  u_char *spu_data_ptr = (u_char *) spu->data;
  float o;
  
  /* don't know why this can happen - but it does happen */
  if ((spu->width <= 0) || (spu->height <= 0) ||
      (spu->width > 1024) || (spu->height > 1024)) {
    fprintf (stderr, "width || height out of range.\n");
    return NULL;
  }
  
  for (y = spu->y; y < (spu->height + spu->y); y++) {
    //     clr_ptr1 = (u_char *) (img1 + y * 720 + spu->x);
    for (x = spu->x; x < (spu->width + spu->x); x++) {
      o = ((float) (*spu_data_ptr>>4) / 15.0) * o1;
      //clr_ptr2 = (u_char *) &spu_clut[*spu_data_ptr&0x0f];
      *clr_ptr2 = *spu_data_ptr&0x0f;
      tmp=*spu_data_ptr;
      printf("%X%X",tmp&0x0f,((tmp>>4)&0x0f));
      spu_data_ptr ++;
      
      //   printf("%d ",(*clr_ptr2++));
      //   printf("%d ",(*clr_ptr2++));
      //   printf("%d ",(*clr_ptr2++));
      //   printf("%d \n",(*clr_ptr2++));
    }
    printf("\n");
  }
  
  return 0;
}

void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) {

  spudec_decoder_t *this = (spudec_decoder_t *) this_gen;

  uint8_t     *current = buf->content;
  /* uint8_t     *end = buf->content + buf->size; */

  printf ("spudec_decode_data\n");  

  if (!this->spu) {
    this->spu = this->vo_out->get_overlay (this->vo_out);
  }

  /* FIXME: shouldn't happen, but get_overlay function isn't implemented yet */
  if (!this->spu)
    return;

  if (!spuParseHdr (this->spu, current, buf->size)) {
    spuParseData (this->spu);
    printf("X=%d Y=%d w=%d h=%d\n",
	   this->spu->x,this->spu->y,
	   this->spu->width,this->spu->height);
    /* overlay_txt(this->spu,1.0); Just for test purposes */
    this->spu->PTS = buf->PTS;
    this->vo_out->queue_overlay (this->vo_out, this->spu);
    this->spu = NULL;
  }
  
}

void spudec_close (spu_decoder_t *this_gen) {

  /* spudec_decoder_t *this = (spudec_decoder_t *) this_gen;  */

//  if (this->output_open) 
//    this->spu_out->close (this->spu_out);

  /* close (spufile); */
}

static char *spudec_get_id(void) {
  return "spudec";
}

spu_decoder_t *init_spu_decoder_plugin (int iface_version, config_values_t *cfg) {

  spudec_decoder_t *this ;

  if (iface_version != 1)
    return NULL;

  this = (spudec_decoder_t *) malloc (sizeof (spudec_decoder_t));

  this->spu_decoder.interface_version   = 1;
  this->spu_decoder.can_handle          = spudec_can_handle;
  this->spu_decoder.init                = spudec_init;
  this->spu_decoder.decode_data         = spudec_decode_data;
  this->spu_decoder.close               = spudec_close;
  this->spu_decoder.get_identifier      = spudec_get_id;
  
  return (spu_decoder_t *) this;
}