該篇內容簡單的將前兩篇內容組合在一起,創建了2個線程,分別播放音頻和視頻。
1 int main(int argc, char * argv[]) 2 { 3 RtspClient Client; 4 pthread_t audio_th; 5 pthread_t video_th; 6 7 if(argc != 2) { 8 cout << "Usage: " << argv[0] << " <URL>" << endl; 9 cout << "For example: " << endl; 10 cout << argv[0] << " rtsp://127.0.0.1/ansersion" << endl; 11 return 1; 12 } 13 signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */ 14 signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */ 15 rtspClientRequest(&Client, argv[1]); 16 av_register_all(); 17 if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) { 18 fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); 19 Client.DoTEARDOWN(); 20 exit(1); 21 } 22 pthread_create(&audio_th, NULL, audio_thread, (void *)&Client); 23 pthread_create(&video_th, NULL, video_thread, (void *)&Client); 24 25 pthread_join(audio_th, NULL); 26 pthread_join(video_th, NULL); 27 Client.DoTEARDOWN(); 28 29 return 0; 30 }
至此,“解碼篇”內容告一段落,接下來將介紹myRTSPClient的具體實現,以便可以更好的理解音視頻的傳輸機制。
注:
1, 示例源碼編譯需要SDL和ffmpeg,具體可參見解碼視頻的附錄二;
2, 博主編譯環境為 x86_64位ubuntu 16.04,以供參考。
編譯、配置和運行同上一篇:用ffmpeg解碼視頻