41#define LIST_FADE_TIME 250000
42#define LIST_HOLD_TIME 500000
154 return rank ^ rank >> 12;
169 default:
cmp = *
a - *
b;
break;
205#define CMP(a, b) compare_rows(lv, a, b)
209 for (
int row = 0; row < lv->
nb_rows; row++)
210 if (lv->
rows[row] == selected)
225#define LIST_EVENT "Dialogue: 0:00:00.00,9999:00:00.00,"
227static void bprint_box(AVBPrint *script,
const char *style,
int x,
int y,
int w,
int h)
229 av_bprintf(script,
LIST_EVENT "%s,{\\pos(%d,%d)\\p1}m 0 0 l %d 0 %d %d 0 %d{\\p0}\n", style, x, y,
w,
w,
h,
h);
233static void bprint_cell(AVBPrint *script,
const char *style,
int x,
int y,
int right,
int bottom,
const char *text)
235 av_bprintf(script,
LIST_EVENT "%s,{\\pos(%d,%d)\\clip(0,0,%d,%d)}", style, x, y, right, bottom);
295 ListHit hit = { 0, -1, -1, 0 };
304 if (y >= l->
rows_y && line < l->nb_rows) {
318 int k =
r * 552 / 1000;
320 av_bprintf(script,
LIST_EVENT "Ring,{\\an5\\pos(%d,%d)\\p1}m 0 %d b 0 %d %d 0 %d 0 b %d 0 %d %d %d %d "
321 "b %d %d %d %d %d %d b %d %d 0 %d 0 %d{\\p0}\n",
322 cx, cy,
r,
r - k,
r - k,
r,
r + k, 2 *
r,
r - k, 2 *
r,
r, 2 *
r,
r + k,
r + k, 2 *
r,
r, 2 *
r,
323 r - k, 2 *
r,
r + k,
r);
327#define PANEL_COLOR 0xBF000000
328#define HOVER_COLOR 0xCD444444
329#define POPUP_COLOR 0xDF000000
334 "[Script Info]\nScriptType: v4.00+\nPlayResX: %d\nPlayResY: %d\nWrapStyle: 2\nYCbCr Matrix: None\n\n"
336 "Format: Name, Fontname, Fontsize, PrimaryColour, OutlineColour, Bold, Outline, Alignment\n"
337 "Style: Button,Sans,%d,&H80FFFFFF,&H80FFFFFF,0,0,7\n"
338 "Style: Row,Sans,%d,&H00FFFFFF,&H00000000,0,%d,7\n"
339 "Style: Selected,Sans,%d,&H0080D0FF,&H00000000,-1,%d,7\n"
340 "Style: Artist,Sans,%d,&H00C0C0C0,&H00000000,0,%d,7\n"
341 "Style: ArtistSelected,Sans,%d,&H0080D0FF,&H00000000,-1,%d,7\n"
342 "Style: Playing,Sans,%d,&H00FFFFFF,&H00FFFFFF,0,0,7\n"
343 "Style: Hint,Sans,%d,&H00A0A0A0,&H00000000,0,%d,7\n"
344 "Style: ButtonHover,Sans,%d,&H50FFFFFF,&H50FFFFFF,0,0,7\n"
345 "Style: Ring,Sans,%d,&HFF000000,&H00A0A0A0,0,%d,7\n"
346 "Style: Detail,Sans,%d,&H00FFFFFF,&H00000000,0,%d,7\n\n"
347 "[Events]\nFormat: Start, End, Style, Text\n",
365 x +
w / 2, y + l->
font * 5 / 8);
378 const char *style =
r == lv->
selected ?
"Selected" :
"Row";
389 if (
entry->length < 0)
394 av_bprintf(script,
"%"PRId64
":%02d:%02d\n", seconds / 3600, (
int)(seconds / 60 % 60), (
int)(seconds % 60));
396 av_bprintf(script,
"%d:%02d\n", (
int)(seconds / 60), (
int)(seconds % 60));
436 !strcmp(e->
script, script->str)) {
530 SDL_DestroyTexture(lv->
texture);
534 ass_free_track(lv->track);
540static void libass_log(
int libass_level,
const char *fmt, va_list args,
void *opaque)
563 if (!(lv->
texture = SDL_CreateTexture(lv->
renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING,
565 SDL_SetTextureBlendMode(lv->
texture, SDL_BLENDMODE_BLEND) < 0)
569 if (!(lv->library = ass_library_init()))
571 ass_set_message_cb(lv->library, libass_log,
NULL);
572 ass_set_extract_fonts(lv->library, 1);
573 if (!(lv->ass = ass_renderer_init(lv->library))) {
574 ass_library_done(lv->library);
583 ass_process_codec_private(lv->track, styles.str, styles.len);
599static uint32_t blend_over(uint32_t
dst, uint32_t
rgb,
int a,
const uint32_t *reciprocal)
601 int dst_a =
dst >> 24, out_a =
a + (dst_a * (255 -
a) + 127) / 255;
602 uint32_t
out = (uint32_t)out_a << 24;
605 int premultiplied = ((
rgb >>
shift & 0xFF) *
a * 255 + (
dst >>
shift & 0xFF) * dst_a * (255 -
a) + 255 * 127) / (255 * 255);
607 out |=
FFMIN(premultiplied * reciprocal[out_a] >> 16, 255) <<
shift;
617 uint32_t *pixels = (uint32_t *)
entry->pixels;
620 ass_flush_events(lv->track);
621 ass_process_data(lv->track,
entry->script, strlen(
entry->script));
622 for (
int i = 0;
i <
w *
h;
i++)
623 pixels[
i] =
entry->background;
624 for (
const ASS_Image *image = ass_render_frame(lv->ass, lv->track, 0,
NULL); image; image = image->next) {
625 int opacity = 255 - (image->color & 0xFF);
628 for (
int y =
FFMAX(image->dst_y, 0); x0 < x1 && y <
FFMIN(image->dst_y + image->h,
h); y++) {
629 const uint8_t *coverage = image->bitmap + (y - image->dst_y) * image->stride + x0 - image->dst_x;
630 uint32_t *
dst = pixels + y *
w + x0 -
entry->x;
632 for (
int x = 0; x < x1 - x0; x++) {
633 int a = (opacity * coverage[x] + 127) / 255;
661 if (!lv->
bitmap || !SDL_RectEquals(&lv->
rect, &canvas))
668 if (old &&
new && old->
entry == new->entry && SDL_RectEquals(&old->
rect, &new->rect))
671 SDL_UnionRect(&dirty, &old->
rect, &dirty);
673 SDL_UnionRect(&dirty, &new->rect, &dirty);
675 if (
ret >= 0 && dirty.w) {
676 for (
int y = dirty.y; y < dirty.y + dirty.h; y++)
677 memset(lv->
bitmap + (y * lv->
rect.w + dirty.x) * 4, 0, dirty.w * 4);
678 for (
int i = 0;
i < nb;
i++) {
682 if (!SDL_IntersectRect(&strips[
i].
rect, &dirty, &part))
684 for (
int y = part.y; y < part.y + part.h; y++)
685 memcpy(lv->
bitmap + (y * lv->
rect.w + part.x) * 4,
686 entry->pixels + ((y - strips[
i].
rect.y) *
entry->w + part.x - strips[
i].
rect.x) * 4, part.w * 4);
688 SDL_UnionRect(&lv->
dirty, &dirty, &lv->
dirty);
722 if (
len + strlen(text) <
sizeof(lv->
search))
744 for (
int a = 1;
a < 256;
a++)
759 ass_renderer_done(lv->ass);
761 ass_library_done(lv->library);
779 memcpy(
copy, entries, nb_entries *
sizeof(*entries));
782 lv->
rows = (
int *)(
copy + nb_entries);
787 for (
int i = 0;
i < nb_entries;
i++) {
792 for (
int row = 0; row < lv->
nb_rows; row++)
793 if (lv->
rows[row] == previous)
795 for (
int row = 0; row < lv->
nb_rows; row++)
796 if (lv->
rows[row] == selected)
816 SDL_StartTextInput();
940 SDL_Rect *dirty = &lv->
dirty;
945 if (dirty->w && !SDL_UpdateTexture(lv->
texture, dirty, lv->
bitmap + (dirty->y * lv->
rect.w + dirty->x) * 4, lv->
rect.w * 4))
946 *dirty = (SDL_Rect){ 0, 0, 0, 0 };
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Convenience header that includes libavutil's core.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define i(width, name, range_min, range_max)
common internal and external API header
static SDL_Renderer * renderer
int list_view_selected(const ListView *lv)
void list_view_set_size(ListView *lv, int width, int height)
Sets the size of the window the list is drawn into.
static int list_render(ListView *lv)
static int list_strips(ListView *lv, const ListLayout *l, ListStrip **strips, int *nb)
static double list_alpha(const ListView *lv, int64_t now)
static int cache_get(ListView *lv, const SDL_Rect *rect, uint32_t background, const AVBPrint *script, ListCacheEntry **entry)
ListView * list_view_alloc(SDL_Renderer *renderer)
static int compare_tags(const char *a, const char *b)
void list_view_set_playing(ListView *lv, int entry)
Marks the entry as playing, -1 for none.
static void bprint_cell(AVBPrint *script, const char *style, int x, int y, int right, int bottom, const char *text)
static void bprint_row_strip(const ListView *lv, AVBPrint *script, const ListLayout *l, int r)
static void bprint_header_strip(const ListView *lv, AVBPrint *script, const ListLayout *l)
static void bprint_box(AVBPrint *script, const char *style, int x, int y, int w, int h)
static int list_configure(ListView *lv, const ListLayout *l, const SDL_Rect *canvas)
static void list_discard(ListView *lv)
static uint32_t shuffle_rank(const ListView *lv, int index)
int list_view_show(ListView *lv, const ListEntry *entries, int nb_entries, int selected)
Replaces the entries and shows the list, fading it in.
static ListLayout list_layout(const ListView *lv)
static int compare_rows(const ListView *lv, const int *a, const int *b)
int list_view_pinned(const ListView *lv)
static void bprint_ring(AVBPrint *script, int cx, int cy, int r)
int list_view_click(ListView *lv, int x, int y, int *chosen)
Handles a left click at window coordinates: a click on an entry chooses it, a click on a column butto...
void list_view_move(ListView *lv, int delta)
Moves the selection by delta rows.
void list_view_clear_search(ListView *lv)
Clears the search, listing all entries.
void list_view_free(ListView **plv)
void list_view_hover(ListView *lv, int x, int y)
Keeps the mouse position, in window coordinates, -1 when the mouse left the window.
static void cache_entry_free(ListCacheEntry **entry)
static void list_select(ListView *lv, int row)
int list_view_visible(const ListView *lv)
static const struct @063245031310031234025313313056123246302351010020 sort_buttons[LIST_SORT_NB]
static ListHit list_hit(const ListLayout *l, int x, int y)
static int strip_add(ListView *lv, ListStrip **strips, int *nb, SDL_Rect rect, uint32_t background, const AVBPrint *script)
static int strip_render(ListView *lv, ListCacheEntry *entry)
void list_view_pin(ListView *lv, int pinned)
Keeps the list on screen and lets it take the keyboard and text input, or lets it fade out again.
static void cache_make_room(ListView *lv, size_t bytes)
static void list_update_rows(ListView *lv)
int list_view_update(ListView *lv)
Brings the list up to date for the next frame, once the pending input is handled.
void list_view_text(ListView *lv, const char *text)
Appends text typed while the list is pinned to the search, or erases its last character when text is ...
static void list_sort_by(ListView *lv, int key, int seed_step)
void list_view_draw(ListView *lv)
Draws the list onto the window, between its other content and the present.
static void bprint_styles(AVBPrint *script, const ListLayout *l)
int list_view_key(ListView *lv, SDL_Keycode key)
Handles a key while the list is pinned: escape unpins it, up/down move the selection,...
void list_view_clear(ListView *lv)
Removes the entries, which may be freed after this, and resets the sort and the search.
A list overlay for ffplay: entries with title, artist, length and metadata that the user can sort,...
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
Send the specified message to the log if the level is less than or equal to the current av_log_level.
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
void * av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
Add an element of size elem_size to a dynamic array.
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
#define AV_TIME_BASE
Internal time base represented as integer.
static const int16_t alpha[]
static int shift(int a, int b)
#define FFDIFFSIGN(x, y)
Comparator.
Memory handling functions.
static av_always_inline int cmp(MPVEncContext *const s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
#define AV_MSORT(p, tmp, num, type, cmp)
Merge sort, this sort requires a temporary buffer and is stable, its worst case time is O(n log n)
#define FF_ARRAY_ELEMS(a)
AVDictionary * metadata
shown when the mouse is over the entry's symbol, may be NULL
int64_t length
in AV_TIME_BASE units, negative when unknown
int button_y[LIST_SORT_NB]
int button_x[LIST_SORT_NB]
ListSortKey sort[LIST_SORT_NB]
int libass_missing_reported
#define av_malloc_array(a, b)
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
static void copy(const float *p1, float *p2, const int length)