Mercurial > mplayer.hg
comparison command.c @ 25363:fa776bd7ebc4
Support chapter as a property.
author | ulion |
---|---|
date | Fri, 14 Dec 2007 08:33:11 +0000 |
parents | 80804f0631f4 |
children | 31e0937ebe38 |
comparison
equal
deleted
inserted
replaced
25362:74fbb5173956 | 25363:fa776bd7ebc4 |
---|---|
365 return m_property_time_ro(prop, action, arg, | 365 return m_property_time_ro(prop, action, arg, |
366 mpctx->sh_video ? mpctx->sh_video->pts : | 366 mpctx->sh_video ? mpctx->sh_video->pts : |
367 playing_audio_pts(mpctx->sh_audio, | 367 playing_audio_pts(mpctx->sh_audio, |
368 mpctx->d_audio, | 368 mpctx->d_audio, |
369 mpctx->audio_out)); | 369 mpctx->audio_out)); |
370 } | |
371 | |
372 /// Current chapter (RW) | |
373 static int mp_property_chapter(m_option_t *prop, int action, void *arg, | |
374 MPContext *mpctx) | |
375 { | |
376 int chapter; | |
377 float next_pts = 0; | |
378 int chapter_num; | |
379 int step_all; | |
380 char *chapter_name = NULL; | |
381 | |
382 switch (action) { | |
383 case M_PROPERTY_GET: | |
384 if (!arg) | |
385 return M_PROPERTY_ERROR; | |
386 *(int *) arg = demuxer_get_current_chapter(mpctx->demuxer); | |
387 return M_PROPERTY_OK; | |
388 case M_PROPERTY_PRINT: { | |
389 if (!arg) | |
390 return M_PROPERTY_ERROR; | |
391 chapter = demuxer_get_current_chapter(mpctx->demuxer); | |
392 if (chapter < 0) | |
393 return M_PROPERTY_UNAVAILABLE; | |
394 chapter_name = demuxer_chapter_display_name(mpctx->demuxer, chapter); | |
395 if (!chapter_name) | |
396 return M_PROPERTY_UNAVAILABLE; | |
397 *(char **) arg = chapter_name; | |
398 return M_PROPERTY_OK; | |
399 } | |
400 case M_PROPERTY_SET: | |
401 if (!arg) | |
402 return M_PROPERTY_ERROR; | |
403 M_PROPERTY_CLAMP(prop, *(int*)arg); | |
404 chapter = demuxer_get_current_chapter(mpctx->demuxer); | |
405 if (chapter < 0) | |
406 return M_PROPERTY_UNAVAILABLE; | |
407 step_all = *(int *)arg - (chapter + 1); | |
408 chapter += step_all; | |
409 break; | |
410 case M_PROPERTY_STEP_UP: | |
411 case M_PROPERTY_STEP_DOWN: { | |
412 step_all = (arg && *(int*)arg != 0 ? *(int*)arg : 1) | |
413 * (action == M_PROPERTY_STEP_UP ? 1 : -1); | |
414 chapter = demuxer_get_current_chapter(mpctx->demuxer); | |
415 if (chapter < 0) | |
416 return M_PROPERTY_UNAVAILABLE; | |
417 chapter += step_all; | |
418 if (chapter < 0) | |
419 chapter = 0; | |
420 break; | |
421 } | |
422 default: | |
423 return M_PROPERTY_NOT_IMPLEMENTED; | |
424 } | |
425 rel_seek_secs = 0; | |
426 abs_seek_pos = 0; | |
427 chapter = demuxer_seek_chapter(mpctx->demuxer, chapter, 1, | |
428 &next_pts, &chapter_num, &chapter_name); | |
429 if (chapter >= 0) { | |
430 if (next_pts > -1.0) { | |
431 abs_seek_pos = 1; | |
432 rel_seek_secs = next_pts; | |
433 } | |
434 if (chapter_name) | |
435 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, | |
436 MSGTR_OSDChapter, chapter + 1, chapter_name); | |
437 } | |
438 else if (step_all > 0) | |
439 rel_seek_secs = 1000000000.; | |
440 else | |
441 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, | |
442 MSGTR_OSDChapter, 0, MSGTR_Unknown); | |
443 if (chapter_name) | |
444 free(chapter_name); | |
445 return M_PROPERTY_OK; | |
370 } | 446 } |
371 | 447 |
372 /// Demuxer meta data | 448 /// Demuxer meta data |
373 static int mp_property_metadata(m_option_t * prop, int action, void *arg, | 449 static int mp_property_metadata(m_option_t * prop, int action, void *arg, |
374 MPContext * mpctx) { | 450 MPContext * mpctx) { |
1807 M_OPT_MIN, 0, 0, NULL }, | 1883 M_OPT_MIN, 0, 0, NULL }, |
1808 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT, | 1884 { "percent_pos", mp_property_percent_pos, CONF_TYPE_INT, |
1809 M_OPT_RANGE, 0, 100, NULL }, | 1885 M_OPT_RANGE, 0, 100, NULL }, |
1810 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME, | 1886 { "time_pos", mp_property_time_pos, CONF_TYPE_TIME, |
1811 M_OPT_MIN, 0, 0, NULL }, | 1887 M_OPT_MIN, 0, 0, NULL }, |
1888 { "chapter", mp_property_chapter, CONF_TYPE_INT, | |
1889 M_OPT_MIN, 1, 0, NULL }, | |
1812 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST, | 1890 { "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST, |
1813 0, 0, 0, NULL }, | 1891 0, 0, 0, NULL }, |
1814 | 1892 |
1815 // Audio | 1893 // Audio |
1816 { "volume", mp_property_volume, CONF_TYPE_FLOAT, | 1894 { "volume", mp_property_volume, CONF_TYPE_FLOAT, |
1996 /// osd msg template | 2074 /// osd msg template |
1997 const char *osd_msg; | 2075 const char *osd_msg; |
1998 } set_prop_cmd[] = { | 2076 } set_prop_cmd[] = { |
1999 // general | 2077 // general |
2000 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus }, | 2078 { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus }, |
2079 { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL }, | |
2001 // audio | 2080 // audio |
2002 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume }, | 2081 { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume }, |
2003 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus }, | 2082 { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus }, |
2004 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus }, | 2083 { "audio_delay", MP_CMD_AUDIO_DELAY, 0, 0, -1, MSGTR_AVDelayStatus }, |
2005 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio }, | 2084 { "switch_audio", MP_CMD_SWITCH_AUDIO, 1, 0, -1, MSGTR_OSDAudio }, |
2900 | 2979 |
2901 case MP_CMD_KEYDOWN_EVENTS: | 2980 case MP_CMD_KEYDOWN_EVENTS: |
2902 mplayer_put_key(cmd->args[0].v.i); | 2981 mplayer_put_key(cmd->args[0].v.i); |
2903 break; | 2982 break; |
2904 | 2983 |
2905 case MP_CMD_SEEK_CHAPTER:{ | |
2906 int seek = cmd->args[0].v.i; | |
2907 int abs = (cmd->nargs > 1) ? cmd->args[1].v.i : 0; | |
2908 int chap; | |
2909 float next_pts = 0; | |
2910 int num_chapters; | |
2911 char *chapter_name; | |
2912 | |
2913 rel_seek_secs = 0; | |
2914 abs_seek_pos = 0; | |
2915 chap = | |
2916 demuxer_seek_chapter(mpctx->demuxer, seek, abs, | |
2917 &next_pts, &num_chapters, | |
2918 &chapter_name); | |
2919 if (chap != -1) { | |
2920 if (next_pts > -1.0) { | |
2921 abs_seek_pos = 1; | |
2922 rel_seek_secs = next_pts; | |
2923 } | |
2924 if (chapter_name) { | |
2925 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, | |
2926 MSGTR_OSDChapter, chap + 1, chapter_name); | |
2927 free(chapter_name); | |
2928 } | |
2929 } else { | |
2930 if (seek > 0) | |
2931 rel_seek_secs = 1000000000.; | |
2932 else | |
2933 set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, | |
2934 MSGTR_OSDChapter, 0, MSGTR_Unknown); | |
2935 } | |
2936 break; | |
2937 } | |
2938 break; | |
2939 | |
2940 case MP_CMD_SET_MOUSE_POS:{ | 2984 case MP_CMD_SET_MOUSE_POS:{ |
2941 int pointer_x, pointer_y; | 2985 int pointer_x, pointer_y; |
2942 double dx, dy; | 2986 double dx, dy; |
2943 pointer_x = cmd->args[0].v.i; | 2987 pointer_x = cmd->args[0].v.i; |
2944 pointer_y = cmd->args[1].v.i; | 2988 pointer_y = cmd->args[1].v.i; |