Michael Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * AV parser inteface declarations |
| 11 | * |
| 12 | * Copyright (c) 2007 Michael Sevakis |
| 13 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License |
| 16 | * as published by the Free Software Foundation; either version 2 |
| 17 | * of the License, or (at your option) any later version. |
Michael Sevakis | a222f27 | 2007-12-29 19:46:35 +0000 | [diff] [blame] | 18 | * |
| 19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 20 | * KIND, either express or implied. |
| 21 | * |
| 22 | ****************************************************************************/ |
| 23 | #ifndef PARSER_H |
| 24 | #define PARSER_H |
| 25 | |
| 26 | enum stream_formats |
| 27 | { |
| 28 | STREAM_FMT_UNKNOWN = -1, |
| 29 | STREAM_FMT_MPEG_TS, /* MPEG transport stream */ |
| 30 | STREAM_FMT_MPEG_PS, /* MPEG program stream */ |
| 31 | STREAM_FMT_MPV, /* MPEG Video only (1 or 2) */ |
| 32 | STREAM_FMT_MPA, /* MPEG Audio only */ |
| 33 | }; |
| 34 | |
| 35 | /* Structure used by a thread that handles a single demuxed data stream and |
| 36 | * receives commands from the stream manager */ |
| 37 | enum stream_parse_states |
| 38 | { |
| 39 | /* Stream is... */ |
| 40 | SSTATE_SYNC, /* synchronizing by trying to find a start code */ |
| 41 | SSTATE_PARSE, /* parsing the stream looking for packets */ |
| 42 | SSTATE_END, /* at the end of data */ |
| 43 | }; |
| 44 | |
| 45 | enum stream_parse_mode |
| 46 | { |
| 47 | STREAM_PM_STREAMING = 0, /* Next packet when streaming */ |
| 48 | STREAM_PM_RANDOM_ACCESS, /* Random-access parsing */ |
| 49 | }; |
| 50 | |
| 51 | enum stream_parser_flags |
| 52 | { |
| 53 | STREAMF_CAN_SEEK = 0x1, /* Seeking possible for this stream */ |
| 54 | }; |
| 55 | |
| 56 | struct stream_parser |
| 57 | { |
| 58 | /* Common generic parser data */ |
| 59 | enum stream_formats format; /* Stream format */ |
| 60 | uint32_t start_pts; /* The movie start time as represented by |
| 61 | the first audio PTS tag in the |
| 62 | stream converted to half minutes */ |
| 63 | uint32_t end_pts; /* The movie end time as represented by |
| 64 | the maximum audio PTS tag in the |
| 65 | stream converted to half minutes */ |
| 66 | uint32_t duration; /* Duration in PTS units */ |
| 67 | unsigned flags; /* Various attributes set at init */ |
| 68 | struct vo_ext dims; /* Movie dimensions in pixels */ |
| 69 | uint32_t last_seek_time; |
| 70 | int (*next_data)(struct stream *str, enum stream_parse_mode type); |
| 71 | union /* A place for reusable no-cache parameters */ |
| 72 | { |
| 73 | struct str_sync_data sd; |
| 74 | } parms; |
| 75 | }; |
| 76 | |
| 77 | extern struct stream_parser str_parser; |
| 78 | |
| 79 | /* MPEG parsing */ |
| 80 | uint8_t * mpeg_parser_scan_start_code(struct stream_scan *sk, uint32_t code); |
| 81 | unsigned mpeg_parser_scan_pes(struct stream_scan *sk); |
| 82 | uint32_t mpeg_parser_scan_scr(struct stream_scan *sk); |
| 83 | uint32_t mpeg_parser_scan_pts(struct stream_scan *sk, unsigned id); |
| 84 | off_t mpeg_stream_stream_seek_PTS(uint32_t time, int id); |
| 85 | |
| 86 | /* General parsing */ |
| 87 | bool parser_init(void); |
| 88 | void str_initialize(struct stream *str, off_t pos); |
| 89 | intptr_t parser_send_video_msg(long id, intptr_t data); |
| 90 | bool parser_get_video_size(struct vo_ext *sz); |
| 91 | int parser_init_stream(void); |
| 92 | void parser_close_stream(void); |
| 93 | static inline bool parser_can_seek(void) |
| 94 | { return str_parser.flags & STREAMF_CAN_SEEK; } |
| 95 | uint32_t parser_seek_time(uint32_t time); |
| 96 | void parser_prepare_streaming(void); |
| 97 | void str_end_of_stream(struct stream *str); |
| 98 | |
| 99 | static inline int parser_get_next_data(struct stream *str, |
| 100 | enum stream_parse_mode type) |
| 101 | { return str_parser.next_data(str, type); } |
| 102 | |
| 103 | #endif /* PARSER_H */ |