This sample program explains how to perform movie playback that supports multiple languages.
The CRI Mana library supports simultaneous playback of sub-audio and the acquisition of subtitles for multiple languages.
What is simultaneous sub-audio playback?
To perform sub-audio track playback, first prepare a movie file with multiple audio tracks. When this movie with multiple audio tracks is played back, this feature enables you to simultaneously play a designated audio track as a sub-audio track for the currently playing audio track.
This allows for multilingual surround playback by playing a voice track as sub-audio at the same time as the 5.1 ch audio.
The following sample code demonstrates how to perform sub-audio playback.
1. Specifying the Sub-audio Track
{
criFwPrt_DebugPrintf("----------------------\n");
criFwPrt_DebugPrintf("Subaudio Track # : %d\n", app_obj->cur_subaudio_track_no);
criFwPrt_DebugPrintf("----------------------\n");
}
void criManaPlayer_SetPlaybackWork(CriManaPlayerHn player, const CriManaPlaybackBasicWorkConfig *config_basic, const CriManaPlaybackExWorkConfig *config_ex, void *work, CriSint32 work_size)
Set playback work area.
CriBool criManaPlayer_GetPlaybackWorkParam(CriManaPlayerHn player, CriManaPlaybackBasicWorkConfig *config_basic, CriManaPlaybackExWorkConfig *config_ex)
Get playback work parameter structure.
void criManaPlayer_SetSubAudioTrack(CriManaPlayerHn player, CriSint32 track)
Set the subaudio track number.
CriUint32 num_channels
Definition: cri_mana.h:630
CriUint32 sampling_rate
Definition: cri_mana.h:629
Playback work parameter structure (basic)
Definition: cri_mana.h:684
Playback work parameter structure (extended)
Definition: cri_mana.h:704
CriManaPlaybackAudioParams sub_audio_params
Definition: cri_mana.h:705
The sub-audio track is specified via the
criManaPlayer_SetSubAudioTrack function before analyzing the header and before starting playback. When a valid track is set, the playback work parameters for the specified track are reflected in the
CriManaPlaybackExWorkConfig structure obtained by the
criManaPlayer_GetPlaybackWorkParam.
If a user allocator has been registered, it is not required to call the
criManaPlayer_SetPlaybackWork function. If a valid sub-audio track has been specified, a work buffer will be allocated automatically in the library.
If you want to disable the sub-audio track playback feature, regardless of the sub-audio settings, pass NULL as the parameter structure for extended playback work to the
criManaPlayer_SetPlaybackWork function or set the use sub_audio_params structure flag in that structure to FALSE.
2. Sub-audio Track Management
In the CRI Mana library, no distinction is made between audio tracks in a movie file regarding whether they are main audio or sub-audio tracks. Which track is played as sub-audio is determined on the application side.
3. Switching Sub-audio Tracks
If you want to switch between different sub-audio tracks during movie playback when there are multiple available sub-audio tracks for different languages, stop the movie playback, set the new sub-audio track, and then resume movie playback.
If you want to resume playback from the point when the audio was switched, save the last obtained frame number and then seek to that frame for playback.
Subtitles
The CRI Mana library can get subtitle information embedded into a movie during encoding at runtime.
1. Checking for the Existence of Subtitles
You can check to see if there is any subtitle data in a movie by looking at the movie information before you begin playback.
CriManaMovieInfo Structure Subtitle Related Member Variables
Variable Name | Description |
num_subtitle_channels | The number of subtitle channels in the movie file. |
max_subtitle_size | The maximum size of the subtitle data. Use this as a reference when allocating the buffer size for subtitles. |
2. Specifying the Subtitle Channel to Get
if (app_obj->mvinf.num_subtitle_channels > 0) {
criManaPlayerSetSubtitleChannel(app_obj->player, app_obj->cur_subtitle_channel_no);
}
Use the
criManaPlayer_SetSubtitleChannel function to set the subtitle channel number you want to get. Unlike with sub-audio track specification, this function can be used to switch to a different subtitle channel number even during playback. However, when the subtitle channel is switched during playback, the subtitles will only be switched starting from the next subtitle data.
If there is no data in the specified subtitle channel, you cannot get the subtitles.
3. Getting Subtitle Data
CriUint32 criManaPlayer_GetSubtitleOnTime(CriManaPlayerHn player, CriUint8 *bufptr, CriUint32 bufsize)
Get subtitles.
The
criManaPlayer_GetSubtitleOnTime function obtains the subtitle data for the current playback time that is stored in the buffer allocated by the application If the subtitle data is larger than the buffer size specified in the parameters, get only the subtitles equivalent to the buffer size and the rest will be discarded.
If there is no subtitle data to display, the subtitle buffer will be cleared to zero. Therefore, this enables an application to perform subtitle playback by continuously displaying the contents of the subtitle buffer.
If a subtitle channel has been set, you must call the above subtitle acquisition function in the main loop of the application during movie playback. If you do not get subtitles when a subtitle channel is enabled, the subtitle data cannot be expended and the movie playback will stop.
4. Subtitle Data Render Processing
The CRI Mana library does not perform any processing for subtitle rendering. All subtitle rendering must be performed by the application, including font processing. For the sake of simplicity, this sample program displays the subtitles as text in the debug information window instead of the movie rendering window.