@@ -344,7 +344,7 @@ static void clock_cb(const pj_timestamp *ts, void *user_data)
344344 status = pjmedia_vid_codec_decode (decoder , 1 , & read_frame ,
345345 (unsigned )write_frame .size ,
346346 & write_frame );
347- if (status != PJ_SUCCESS )
347+ if (status != PJ_SUCCESS || write_frame . size == 0 )
348348 return ;
349349 } else {
350350 write_frame = read_frame ;
@@ -666,8 +666,10 @@ static int main_func(int argc, char *argv[])
666666
667667 /* Create file player */
668668 status = create_file_player (pool , play_file .file_name , & play_port );
669- if (status != PJ_SUCCESS )
669+ if (status != PJ_SUCCESS ) {
670+ app_perror (THIS_FILE , "Error opening file" , status );
670671 goto on_exit ;
672+ }
671673
672674 /* Collect format info */
673675 file_vfd = pjmedia_format_get_video_format_detail (& play_port -> info .fmt ,
@@ -677,19 +679,18 @@ static int main_func(int argc, char *argv[])
677679 pjmedia_fourcc_name (play_port -> info .fmt .id , fmt_name ),
678680 (1.0 * file_vfd -> fps .num /file_vfd -> fps .denum )));
679681
680- /* Allocate file read buffer */
681- play_file .read_buf_size = PJMEDIA_MAX_VIDEO_ENC_FRAME_SIZE ;
682- play_file .read_buf = pj_pool_zalloc (pool , play_file .read_buf_size );
683-
684682 /* Create decoder, if the file and the stream uses different codec */
685- if (codec_info -> fmt_id != (pjmedia_format_id )play_port -> info .fmt .id ) {
683+ if (codec_info -> dec_fmt_id [0 ] !=
684+ (pjmedia_format_id )play_port -> info .fmt .id )
685+ {
686686 const pjmedia_video_format_info * dec_vfi ;
687687 pjmedia_video_apply_fmt_param dec_vafp = {0 };
688688 const pjmedia_vid_codec_info * codec_info2 ;
689689 pjmedia_vid_codec_param codec_param2 ;
690690
691691 /* Find decoder */
692692 status = pjmedia_vid_codec_mgr_get_codec_info2 (NULL ,
693+ (pjmedia_format_id )
693694 play_port -> info .fmt .id ,
694695 & codec_info2 );
695696 if (status != PJ_SUCCESS )
@@ -712,6 +713,7 @@ static int main_func(int argc, char *argv[])
712713 goto on_exit ;
713714
714715 codec_param2 .dir = PJMEDIA_DIR_DECODING ;
716+ codec_param2 .packing = PJMEDIA_VID_PACKING_WHOLE ;
715717 status = play_decoder -> op -> open (play_decoder , & codec_param2 );
716718 if (status != PJ_SUCCESS )
717719 goto on_exit ;
@@ -726,9 +728,30 @@ static int main_func(int argc, char *argv[])
726728 dec_vafp .size = file_vfd -> size ;
727729 (* dec_vfi -> apply_fmt )(dec_vfi , & dec_vafp );
728730
731+ /* Allocate file read buffer */
732+ play_file .read_buf_size = PJMEDIA_MAX_VIDEO_ENC_FRAME_SIZE ;
733+ play_file .read_buf = pj_pool_zalloc (pool , play_file .read_buf_size );
734+
729735 /* Allocate buffer to receive decoder output */
730736 play_file .dec_buf_size = dec_vafp .framebytes ;
731737 play_file .dec_buf = pj_pool_zalloc (pool , play_file .dec_buf_size );
738+ } else {
739+ const pjmedia_video_format_info * dec_vfi ;
740+ pjmedia_video_apply_fmt_param dec_vafp = {0 };
741+
742+ /* Get decoder format info and apply param */
743+ dec_vfi = pjmedia_get_video_format_info (NULL ,
744+ play_port -> info .fmt .id );
745+ if (!dec_vfi || !dec_vfi -> apply_fmt ) {
746+ status = PJ_ENOTSUP ;
747+ goto on_exit ;
748+ }
749+ dec_vafp .size = file_vfd -> size ;
750+ (* dec_vfi -> apply_fmt )(dec_vfi , & dec_vafp );
751+
752+ /* Allocate file read buffer */
753+ play_file .read_buf_size = dec_vafp .framebytes ;
754+ play_file .read_buf = pj_pool_zalloc (pool , play_file .read_buf_size );
732755 }
733756
734757 /* Create player clock */
@@ -935,6 +958,10 @@ static int main_func(int argc, char *argv[])
935958 /* Start deinitialization: */
936959on_exit :
937960
961+ if (status != PJ_SUCCESS ) {
962+ app_perror (THIS_FILE , "Something wrong" , status );
963+ }
964+
938965 /* Stop video devices */
939966 if (capture )
940967 pjmedia_vid_port_stop (capture );
0 commit comments