summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/ltm.c
blob: c27f0f6fab8561f1097a64a6eed1b7785921c74b (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
/*
** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $
** Tag methods
** See Copyright Notice in lua.h
*/


#include <string.h>

#define ltm_c
#define LUA_CORE

#include "lua.h"

#include "lobject.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"



const char *const luaT_typenames[] = {
  "nil", "boolean", "userdata", "number",
  "string", "table", "function", "userdata", "thread",
  "proto", "upval"
};


void luaT_init (lua_State *L) {
  static const char *const luaT_eventname[] = {  /* ORDER TM */
    "__index", "__newindex",
    "__gc", "__mode", "__eq",
    "__add", "__sub", "__mul", "__div", "__mod",
    "__pow", "__unm", "__len", "__lt", "__le",
    "__concat", "__call"
  };
  int i;
  for (i=0; i<TM_N; i++) {
    G(L)->tmname[i] = luaS_new(L, luaT_eventname[i]);
    luaS_fix(G(L)->tmname[i]);  /* never collect these names */
  }
}


/*
** function to be used with macro "fasttm": optimized for absence of
** tag methods
*/
const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
  const TValue *tm = luaH_getstr(events, ename);
  lua_assert(event <= TM_EQ);
  if (ttisnil(tm)) {  /* no tag method? */
    events->flags |= cast_byte(1u<<event);  /* cache this fact */
    return NULL;
  }
  else return tm;
}


const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
  Table *mt;
  switch (ttype(o)) {
    case LUA_TTABLE:
      mt = hvalue(o)->metatable;
      break;
    case LUA_TUSERDATA:
      mt = uvalue(o)->metatable;
      break;
    default:
      mt = G(L)->mt[ttype(o)];
  }
  return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject);
}

hroma_width, chroma_height; unsigned int byte_rate; unsigned int vbv_buffer_size; uint32_t flags; unsigned int picture_width, picture_height; unsigned int display_width, display_height; unsigned int pixel_width, pixel_height; unsigned int frame_period; uint8_t profile_level_id; uint8_t colour_primaries; uint8_t transfer_characteristics; uint8_t matrix_coefficients; } mpeg2_sequence_t; #define GOP_FLAG_DROP_FRAME 1 #define GOP_FLAG_BROKEN_LINK 2 #define GOP_FLAG_CLOSED_GOP 4 typedef struct mpeg2_gop_s { uint8_t hours; uint8_t minutes; uint8_t seconds; uint8_t pictures; uint32_t flags; } mpeg2_gop_t; #define PIC_MASK_CODING_TYPE 7 #define PIC_FLAG_CODING_TYPE_I 1 #define PIC_FLAG_CODING_TYPE_P 2 #define PIC_FLAG_CODING_TYPE_B 3 #define PIC_FLAG_CODING_TYPE_D 4 #define PIC_FLAG_TOP_FIELD_FIRST 8 #define PIC_FLAG_PROGRESSIVE_FRAME 16 #define PIC_FLAG_COMPOSITE_DISPLAY 32 #define PIC_FLAG_SKIP 64 #define PIC_FLAG_TAGS 128 #define PIC_MASK_COMPOSITE_DISPLAY 0xfffff000 typedef struct mpeg2_picture_s { unsigned int temporal_reference; unsigned int nb_fields; uint32_t tag, tag2; uint32_t flags; struct { int x, y; } display_offset[3]; } mpeg2_picture_t; typedef struct mpeg2_fbuf_s { uint8_t * buf[MPEG2_COMPONENTS]; void * id; } mpeg2_fbuf_t; typedef struct mpeg2_info_s { const mpeg2_sequence_t * sequence; const mpeg2_gop_t * gop; const mpeg2_picture_t * current_picture; const mpeg2_picture_t * current_picture_2nd; const mpeg2_fbuf_t * current_fbuf; const mpeg2_picture_t * display_picture; const mpeg2_picture_t * display_picture_2nd; const mpeg2_fbuf_t * display_fbuf; const mpeg2_fbuf_t * discard_fbuf; const uint8_t * user_data; unsigned int user_data_len; } mpeg2_info_t; typedef struct mpeg2dec_s mpeg2dec_t; typedef struct mpeg2_decoder_s mpeg2_decoder_t; typedef enum { STATE_INTERNAL_NORETURN = -1, STATE_BUFFER = 0, STATE_SEQUENCE = 1, STATE_SEQUENCE_REPEATED = 2, STATE_SEQUENCE_MODIFIED = 3, STATE_GOP = 4, STATE_PICTURE = 5, STATE_SLICE_1ST = 6, STATE_PICTURE_2ND = 7, STATE_SLICE = 8, STATE_END = 9, STATE_INVALID = 10, STATE_INVALID_END = 11, } mpeg2_state_t; typedef struct mpeg2_convert_init_s { unsigned int id_size; unsigned int buf_size[MPEG2_COMPONENTS]; void (* start)(void * id, const mpeg2_fbuf_t * fbuf, const mpeg2_picture_t * picture, const mpeg2_gop_t * gop); void (* copy)(void * id, uint8_t * const * src, unsigned int v_offset); } mpeg2_convert_init_t; typedef enum { MPEG2_CONVERT_SET = 0, MPEG2_CONVERT_STRIDE = 1, MPEG2_CONVERT_START = 2 } mpeg2_convert_stage_t; typedef int mpeg2_convert_t (int stage, void * id, const mpeg2_sequence_t * sequence, int stride, void * arg, mpeg2_convert_init_t * result); int mpeg2_convert (mpeg2dec_t * mpeg2dec, mpeg2_convert_t convert, void * arg); int mpeg2_stride (mpeg2dec_t * mpeg2dec, int stride); void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[MPEG2_COMPONENTS], void * id); void mpeg2_custom_fbuf (mpeg2dec_t * mpeg2dec, int custom_fbuf); mpeg2dec_t * mpeg2_init (void); const mpeg2_info_t * mpeg2_info (mpeg2dec_t * mpeg2dec); void mpeg2_close (mpeg2dec_t * mpeg2dec); void mpeg2_buffer (mpeg2dec_t * mpeg2dec, uint8_t * start, uint8_t * end); int mpeg2_getpos (mpeg2dec_t * mpeg2dec); mpeg2_state_t mpeg2_parse (mpeg2dec_t * mpeg2dec); void mpeg2_reset (mpeg2dec_t * mpeg2dec, int full_reset); void mpeg2_skip (mpeg2dec_t * mpeg2dec, int skip); void mpeg2_slice_region (mpeg2dec_t * mpeg2dec, int start, int end); void mpeg2_tag_picture (mpeg2dec_t * mpeg2dec, uint32_t tag, uint32_t tag2); void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[MPEG2_COMPONENTS], uint8_t * forward_fbuf[MPEG2_COMPONENTS], uint8_t * backward_fbuf[MPEG2_COMPONENTS]); void mpeg2_slice (mpeg2_decoder_t * decoder, int code, const uint8_t * buffer); int mpeg2_guess_aspect (const mpeg2_sequence_t * sequence, unsigned int * pixel_width, unsigned int * pixel_height); typedef enum { MPEG2_ALLOC_MPEG2DEC = 0, MPEG2_ALLOC_CHUNK = 1, MPEG2_ALLOC_YUV = 2, MPEG2_ALLOC_CONVERT_ID = 3, MPEG2_ALLOC_CONVERTED = 4, MPEG_ALLOC_CODEC_MALLOC, MPEG_ALLOC_CODEC_CALLOC, MPEG_ALLOC_MPEG2_BUFFER, MPEG_ALLOC_AUDIOBUF, MPEG_ALLOC_PCMOUT, MPEG_ALLOC_DISKBUF, __MPEG_ALLOC_FIRST = -256, } mpeg2_alloc_t; void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason); #if 0 void mpeg2_free (void * buf); #endif /* allocates a dedicated buffer and locks all previous allocation in place */ void * mpeg2_bufalloc(unsigned size, mpeg2_alloc_t reason); /* clears all non-dedicated buffer space */ void mpeg2_mem_reset(void); void mpeg2_alloc_init(unsigned char* buf, int mallocsize); #endif /* MPEG2_H */