You are on page 1of 47

모바일정보통신 종합설계

(4주차, 5주차 과제 지도)


Lab3 & 4: Video Stream

2022년 가을 학기
가톨릭대학교 정보통신전자공학부
정윤찬 교수
4.1 multimedia networking applications
Multimedia: audio
❖ analog audio signal sa
mpled at constant rate
quantization
▪ telephone: 8,000 sa
quantized
error value of
mples/sec analog value

audio signal amplitude


▪ CD music: 44,100 sa analog

mples/sec signal

❖ each sample quantized,


i.e., rounded
▪ e.g., 28=256 possibl time
e quantized values
sampling rate
▪ each quantized valu (N sample/sec)

e represented by bit
s, e.g., 8 bits for 256
values

Multimedia Networking 4-3


Multimedia: audio
❖ example: 8,000 samples/s
ec, 256 quantized values:
64,000 bps quantization
error
quantized
value of
❖ receiver converts bits bac analog value

audio signal amplitude


k to analog signal: analog

▪ some quality reduction signal

example rates
❖ CD: 1.411 Mbps time

❖ MP3: 96, 128, 160 kbps sampling rate


(N sample/sec)
❖ Internet telephony: 5.3 kb
ps and up

Multimedia Networking 4-4


spatial coding example: instead

Multimedia: video of sending N values of same


color (all purple), send only two
values: color value (purple) and
number of repeated values (N)
❖video: sequence of images
displayed at constant rate ……………………...…
……………………...…
▪ e.g. 24 images/sec
❖digital image: array of pixel
s
▪ each pixel represented
by bits
❖coding: use redundancy wit frame i
hin and between images to
decrease # bits used to enc
ode image temporal coding example:
▪ spatial (within image) instead of sending
complete frame at i+1,
▪ temporal (from one ima send only differences from
ge to next) frame i

frame i+1
Multimedia Networking 4-5
Multimedia: video
spatial coding example: instead
of sending N values of same
color (all purple), send only two
❖ CBR: (constant bit rate): v values: color value (purple) and
number of repeated values (N)
ideo encoding rate fixed
……………………...…
❖ VBR: (variable bit rate): v ……………………...…
ideo encoding rate chang
es as amount of spatial, t
emporal coding changes
❖ examples:
▪ MPEG 1 (CD-ROM) 1.5
Mbps
frame i
▪ MPEG2 (DVD) 3-6 Mb
ps
▪ MPEG4 (often used in temporal coding example:
Internet, < 1 Mbps) instead of sending
complete frame at i+1,
▪ MP4는 MPEG-4 Part.14 규 send only differences from
격을 토대로 발표된 확장자 frame i
이자 컨테이너
frame i+1
Multimedia Networking 4-6
Multimedia networking: 3 application types
❖streaming, stored audio, video
▪ streaming: can begin playout before downloading ent
ire file
▪ stored (at server): can transmit faster than audio/vide
o will be rendered (implies storing/buffering at client)
▪ e.g., YouTube
• conversational voice/video over IP
▪ interactive nature of human-to-human conversation li
mits delay tolerance
▪ e.g., Skype
❖streaming live audio, video
▪ e.g., live sporting event

Multimedia Networking 4-7


H.264 비디오 압축 방식(MPEG-4
Part 2보다 발전된 비디오 코딩이
라 AVC(Advanced Video Coding)

MJPEG 비디오 압축 방식
(본 과제에서 사용하는 방식)

MJPEG is a format of multimedia data, which


uses a frame-by-frame video track
compression technology JPEG. This codec
does not encode the difference (movement)
between frames, whereby the image in some
places does not turn out smooth enough. It is
actively used in web and IP-cameras.

본 과제에 이용할 MJPEG 영상 (10 프레임/초)


4.2 Streaming stored video

2. video
sent
1. video 3. video received,
recorded (e.g. network delay played out at client
, 30 frames/se (fixed in this e (30 frames/sec) time
c) xample)

streaming: at this time, client


playing out early part of video,
while server still sending later
part of video

Multimedia Networking 4-8


1. RTSP(Real Time Streaming Protocol)

ㅇ 실시간 멀티미디어 스트림을 제어하기 위한 스트리밍 프로토콜

ㅇ RealNetworks사,Netscape사,IBM사,콜롬비아대학 등이 공동 개발, IETF에서 표준화


- 관련표준 : RFC 2326 (1998)

2. RTSP 특징

ㅇ 클라이언트/서버 형태로 동작
- 구조,문법,동작방식이 HTTP 와 매우 유사

ㅇ 세션 관리
- 다지점 다수개의 멀티미디어 세션의 설정과 제어가 RTSP에 의하여 제어됨
- RTSP의 자원 관리 셋업 및 예약은 RSVP를 가지고 사용 가능
ㅇ 여러 프로토콜들이 관련됨
- 실제 멀티미디어 정보의 실시간 전송 매커니즘은 RTP (Real Time Protocol)/RTCP (Real
Time Control Protocol)에 기본을 두고 있음
. RTP/RTCP : 오디오,비디오 등에서 시간 동기화된 스트림을 생성 및 제어함

- 신뢰적인 TCP, 비신뢰적인 UDP 등 다양한 전송 프로토콜 위에서 동작 가능


. 주로 UDP 위에서 동작
.. 이러한 프로토콜의 도움을 받아 RTSP/RTP(RTCP) 실시간 패킷이 전달됨

3. 스트리밍 재생과 관련된 제어 명령어 예


ㅇ Setup(연결 설정), Play(재생), Forward, Rewind, Pause(일시 멈춤), Stop(완전 정지),
Resume(다시 시작), Record, Teardown(연결 해제) 등
- 가정용 VCR을 인터넷에 적용한 것임
인터넷 웹에 의한 RTSP 구현

본 과제에서 구현
할 부분
RTP 구조
RTP 구조 ㅇ 제어비트 : 9 비트
- Ver (버젼) : 2 비트
. 현재 RTP 버젼은, 2 (RFC 3550)
- P (padding) : 1 비트
. 1 이면 실제 유료부하 끝에 덧붙여진 패딩 데이터 있음
. 응용프로그램이 32 비트 같은 정수배 단위로 RTP 패킷 페이로드 구성을 위함
- X (extension) : 1 비트
. 1 이면 가변길이 헤더 확장(Extension Header)이 있음을 나타냄
- CC (CSRC Count) : 4 비트
. 기본 헤더 바로 뒤에 나타나는 CSRC(Countributing SouRCe) ID의 갯수
. 여러 미디어가 합성되는 경우에, 그 개수를 CC로써 나타내고,
모두의 기준 동기를 맞추려면 SRRC ID로써 이를 나타냄
- M (Marker) : 1 비트
. 이벤트 발생이 시작되었음을 알림

ㅇ 유료부하 타입(Payload type) : (7 비트) 오디오/비디오 인코딩(코덱) 종류


- 오디오 타입 번호 예)
. 0 -> G.711 PCM(mu-law), 샘플링주파수 8000 Hz
. 3 -> GSM, 샘플링주파수 8000 Hz ㅇ 순서번호(Sequence number) : (16 비트)
. 4 -> G.723, 샘플링주파수 8000 Hz - 패킷 손실 검출 및 순서 재구성
. 6 -> DVI4 (ADPCM), 샘플링주파수 16000 Hz . 초기값은 랜덤이고, 매 패킷 마다 1씩 증가
. 7 -> LPC, 샘플링주파수 8000 Hz ㅇ 타임스탬프(Timestamp) : (32 비트)
. 8 -> G.711 PCM(A-Law) 샘플링주파수 8000 Hz - RTP 스트림 내 각 RTP 패킷이 샘플링된 시간관계를 나타냄
. 9 -> G.722, 샘플링주파수 8000 Hz . 랜덤한 초기값부터 시작하며, 통상적으로 카운터에 의해 1씩 증가시킴
. 14 -> MPEG 오디오, 샘플링주파수 90000 Hz
. 15 -> G.728, 샘플링주파수 8000 Hz ㅇ 동기 발신 식별자 (SSRC ID, Synchronization SouRCe ID) : (32 비트)
- 비디오 타입 번호 예) - 원래의 정보 스트림에 대한 식별 (즉, RTP 세션에서 소스 구분하는 고유 번호)
. 26 -> MJPEG, 31 -> H.261, 32 -> MPEG-1 또는 MPEG-2 비디오,
33 -> MPEG-2 TS 등
Lab3: Video Stream 과제 설명
Motion JPEG (M-JPEG or MJPEG) is a video compression format in which each video
frame or interlaced field of a digital video sequence is compressed separately as
a JPEG image. Originally developed for multimedia PC applications, M-JPEG is now used by
video-capture devices such as digital cameras, IP cameras, and webcams, as well as by non-
linear video editing systems.

클라이언트
2. video
Sent every 100 milli seconds

3. video received,
played out at client
1. video (10 frames/sec) time
recorded (10 frames/sec)
서버
streaming: at this time, client
playing out

S의 IP 주소 표시 실

서버 클라이언트 S의 IP 주소 입

SETUP 버 클
시그 링용 TCP 연결 설정
데이터그램 UDP
S SETUP 1 (request_type || 요청 VideoFileName || " RTSP/1.0" ) 생성

S SETUP 2 ("CSeq: " || RTSPSeqNb)

S SETUP 3 ("Transport: ... "|| RTP_RCV_PORT)

S 응 1 ("RTSP/1.0 200 OK" )


S 응 2 ("CSeq: " || RTSPSeqNb)

S 응 3( "Session: " || RTSP_IDT)

PLAY 버 클
S PLAY 1 (request_type || 요청 VideoFileName || " RTSP/1.0" )
S PLAY 2 ("CSeq: " || RTSPSeqNb)

S PLAY 3 ( "Session: " || RTSPid)

S 응 1 ("RTSP/1.0 200 OK" )


S 응 2 ("CSeq: " || RTSPSeqNb)

S 응 3( "Session: " || RTSP_IDT)

#1 Seq#1 Frame RTP Packet


100
milliseconds
TimerPlay #2 Seq#2 Frame RTP Packet
TimerPlay
동작 동작
100
milliseconds
#3 Seq#3 Frame RTP Packet

...
S PAUSE 1 (request_type || 요청 VideoFileName || " RTSP/1.0" ) PAUSE 버 클
TimerPlay 멈춤

...
TimerPlay
S 응 3( "Session: " || RTSP_IDT) 멈춤

PLAY 버 클
S 1 (request_type || 요청 VideoFileName || " RTSP/1.0"

...
PLAY )
100 리초 간격으로 하나의 프레임을 받아 디스플레이하는 클라이언트
Timerplay 동작

100 milli seconds 100 milli seconds 100 milli seconds

RTP datagram arrived RTP datagram arrived RTP datagram arrived


#1 ... #2 #3 time
Write Write Write

ByteBuffer ByteBuffer ByteBuffer

일련의 프레임이 도 하면 타이 를
작동하여 100 리초 간격으로 UDP
을 통하여 하나의 프레임에
해 하는 데이터그램을 어 Image Bit
Map으로 변 한 에 디스플레이
Lab3: Video Stream

1. Client

S의 IP 주소 표시 실

서버 클라이언트 S의 IP 주소 입

SETUP 버 클
시그 링용 TCP 연결 설정
데이터그램 UDP
S SETUP 1 (request_type || 요청 VideoFileName || " RTSP/1.0" ) 생성

S SETUP 2 ("CSeq: " || RTSPSeqNb)

S SETUP 3 ("Transport: ... "|| RTP_RCV_PORT)

S 응 1 ("RTSP/1.0 200 OK" )


S 응 2 ("CSeq: " || RTSPSeqNb)

S 응 3( "Session: " || RTSP_IDT)

PLAY 버 클
S PLAY 1 (request_type || 요청 VideoFileName || " RTSP/1.0" )
S PLAY 2 ("CSeq: " || RTSPSeqNb)

S PLAY 3 ( "Session: " || RTSPid)

S 응 1 ("RTSP/1.0 200 OK" )


S 응 2 ("CSeq: " || RTSPSeqNb)

S 응 3( "Session: " || RTSP_IDT)

#1 Seq#1 Frame RTP Packet


100
milliseconds
TimerPlay #2 Seq#2 Frame RTP Packet
TimerPlay
동작 동작
100
milliseconds
#3 Seq#3 Frame RTP Packet

...
S PAUSE 1 (request_type || 요청 VideoFileName || " RTSP/1.0" ) PAUSE 버 클
TimerPlay 멈춤

...
TimerPlay
S 응 3( "Session: " || RTSP_IDT) 멈춤

PLAY 버 클
S 1 (request_type || 요청 VideoFileName || " RTSP/1.0"

...
PLAY )
Manifest.xml 만들기
화면 설계 목표

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" <Button
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/button_pause"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
tools:context=".MainActivity"> android:layout_above="@+id/button_teardown"
android:layout_alignParentStart="true"
<ImageView
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="PAUSE" />
android:id="@+id/imageView"
android:scaleType="fitXY" <Button
android:layout_alignRight="@+id/button_setup" android:id="@+id/button_teardown"
android:layout_alignEnd="@+id/button_setup" android:layout_width="wrap_content"
android:layout_alignParentLeft="true" android:layout_height="wrap_content"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_above="@+id/button_setup"
android:layout_alignParentEnd="true"
android:layout_below="@+id/editText_ServerIP" />
android:layout_alignParentBottom="true"
<Button android:text="TEAR DOWN" />
android:id="@+id/button_setup"
android:layout_width="wrap_content" <EditText
android:layout_height="wrap_content" android:id="@+id/editText_ServerIP"
android:layout_above="@+id/button_play" android:layout_width="wrap_content"
android:layout_alignParentStart="true" android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignEnd="@+id/imageView"
android:text="SET UP" />
android:layout_alignParentStart="true"
<Button android:layout_alignParentTop="true"
android:id="@+id/button_play" android:hint="Enter Server IP Address:" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button_pause" </RelativeLayout>
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:text="PLAY" />
⚫ dimens.xml (Should be place under res -> values folder…. To
create right click values > New > Values Resource File > type
“dimens.xml” )
Video Client 설계 완성 확인
클라이언트 파트만 실 한 모습
Lab4: Video Stream

1. Server

S의 IP 주소 표시 실

서버 클라이언트 S의 IP 주소 입

SETUP 버 클
시그 링용 TCP 연결 설정
데이터그램 UDP
S SETUP 1 (request_type || 요청 VideoFileName || " RTSP/1.0" ) 생성

S SETUP 2 ("CSeq: " || RTSPSeqNb)

S SETUP 3 ("Transport: ... "|| RTP_RCV_PORT)

S 응 1 ("RTSP/1.0 200 OK" )


S 응 2 ("CSeq: " || RTSPSeqNb)

S 응 3( "Session: " || RTSP_IDT)

PLAY 버 클
S PLAY 1 (request_type || 요청 VideoFileName || " RTSP/1.0" )
S PLAY 2 ("CSeq: " || RTSPSeqNb)

S PLAY 3 ( "Session: " || RTSPid)

S 응 1 ("RTSP/1.0 200 OK" )


S 응 2 ("CSeq: " || RTSPSeqNb)

S 응 3( "Session: " || RTSP_IDT)

#1 Seq#1 Frame RTP Packet


100
milliseconds
TimerPlay #2 Seq#2 Frame RTP Packet
TimerPlay
동작 동작
100
milliseconds
#3 Seq#3 Frame RTP Packet

...
S PAUSE 1 (request_type || 요청 VideoFileName || " RTSP/1.0" ) PAUSE 버 클
TimerPlay 멈춤

...
TimerPlay
S 응 3( "Session: " || RTSP_IDT) 멈춤

PLAY 버 클
S 1 (request_type || 요청 VideoFileName || " RTSP/1.0"

...
PLAY )
Manifest.xml 만들기
제공한 소스를 복사
하여 붙여 놓기 한
ACTIVITY_MAIN.XML
모습
⚫ dimens.xml (Should be place under res -> values folder…. To
create right click values > New > Values Resource File > type
“dimens.xml” )
Video Server 설계 완성 확인
서버쪽 안드로이드 장
치에 movie.Mjpeg 저
장 및 파일관리자로
경로 확인

또 다른 LG-V498을 사용하여 서버 프로그램 실


보고서 포함 화면 1
보고서 포함 화면 2
보고서 포함 화면 3
보고서 포함 화면 4

S의 IP 주소 표시 실

서버 클라이언트 S의 IP 주소 입

SETUP 버 클
시그 링용 TCP 연결 설정
데이터그램 UDP
S SETUP 1 (request_type || 요청 VideoFileName || " RTSP/1.0" ) 생성

S SETUP 2 ("CSeq: " || RTSPSeqNb)

S SETUP 3 ("Transport: ... "|| RTP_RCV_PORT)

S 응 1 ("RTSP/1.0 200 OK" )


S 응 2 ("CSeq: " || RTSPSeqNb)

S 응 3( "Session: " || RTSP_IDT)

PLAY 버 클
S PLAY 1 (request_type || 요청 VideoFileName || " RTSP/1.0" )
S PLAY 2 ("CSeq: " || RTSPSeqNb)

S PLAY 3 ( "Session: " || RTSPid)

S 응 1 ("RTSP/1.0 200 OK" )


S 응 2 ("CSeq: " || RTSPSeqNb)

S 응 3( "Session: " || RTSP_IDT)

#1 Seq#1 Frame RTP Packet


100
milliseconds
TimerPlay #2 Seq#2 Frame RTP Packet
TimerPlay
동작 동작
100
milliseconds
#3 Seq#3 Frame RTP Packet

...
S PAUSE 1 (request_type || 요청 VideoFileName || " RTSP/1.0" ) PAUSE 버 클
TimerPlay 멈춤

...
TimerPlay
S 응 3( "Session: " || RTSP_IDT) 멈춤

PLAY 버 클
S 1 (request_type || 요청 VideoFileName || " RTSP/1.0"

...
PLAY )
Video Client 프로그램 해석

S의 IP 주소 표시 실

서버 클라이언트 S의 IP 주소 입

SETUP 버 클
시그 링용 TCP 연결 설정
데이터그램 UDP
S SETUP 1 (request_type || 요청 VideoFileName || " RTSP/1.0" ) 생성

S SETUP 2 ("CSeq: " || RTSPSeqNb)

S SETUP 3 ("Transport: ... "|| RTP_RCV_PORT)

S 응 1 ("RTSP/1.0 200 OK" )


S 응 2 ("CSeq: " || RTSPSeqNb)

S 응 3( "Session: " || RTSP_IDT)

PLAY 버 클
S PLAY 1 (request_type || 요청 VideoFileName || " RTSP/1.0" )
S PLAY 2 ("CSeq: " || RTSPSeqNb)

S PLAY 3 ( "Session: " || RTSPid)

S 응 1 ("RTSP/1.0 200 OK" )


S 응 2 ("CSeq: " || RTSPSeqNb)

S 응 3( "Session: " || RTSP_IDT)

#1 Seq#1 Frame RTP Packet


100
milliseconds
TimerPlay #2 Seq#2 Frame RTP Packet
TimerPlay
동작 동작
100
milliseconds
#3 Seq#3 Frame RTP Packet

...
S PAUSE 1 (request_type || 요청 VideoFileName || " RTSP/1.0" ) PAUSE 버 클
TimerPlay 멈춤

...
TimerPlay
S 응 3( "Session: " || RTSP_IDT) 멈춤

PLAY 버 클
S 1 (request_type || 요청 VideoFileName || " RTSP/1.0"

...
PLAY )
VIDEO Server 프로그램 해석
모바일정보통신 종합설계
4, 5 주차 과제 지도를
마칩니다.
감사합니다.

You might also like