Ptp:
Image transmission protocol abbreviation, all called: Picture Transfer Protocol;
PTP is one of the earliest standards developed by Kodak and Microsoft, which conforms to this standard, which can be better shared by systems and applications after accessing the Windows XP system, especially in the network transmission, the system can directly access these devices used to set up the network album image Upload, The transmission of pictures when chatting on the Internet.
MTP:
The media Transfer Protocol, which is an extension of the PTP(Picture Transfer Protocol) protocol, is primarily used to transfer media files, where the value of the application is to synchronize the license of DRM files. There are currently only WMP10 (Windows Media Player 10) and WMP11 (Windows Media Player 11) two editions that support MTP protocols, WMP11 has added support for playlist and album art, Getobjectproplist replaced the WMP10 getobjectinfo command when obtaining media file information.
MTP supports the transfer of movie files on digital audio players to music files and mobile media players, which is part of the Windows Media Framework and is therefore closely related to Windows Media Player. Windows Vista has built-in support for MTP that supports MTP in Windows XP and requires the installation of window Media Player 10 or later. Mac and Linux have software packages that support MTP.
The application of MTP is divided into two roles, one being as initiator and the other as responder. For example: WMP (Windows Media player) is initiator, and the portable Media player device is a responder. Responder are passive responses to initiator's commands, and will not initiate commands. The main purpose is to transfer media files (medium file) and to correlate metadata from (to) devices, with optional additional support for remote control of the device, and to read and set device parameters such as special DRM-related restricted content device parameters. The device can also send events (event) to the host.
MTP can be implemented either on the USB protocol or on the TCP/IP protocol, which belongs to the upper level application protocol and not the underlying transport protocol. Most devices currently use USB-based protocols. The equipment supporting MTP on the market has Motorola's Z6, U9, E8 and so on, as well as the Sony NWZ-A81X series. In short, more and more devices are beginning to support MTP. Microsoft Official has a PlaysForSure certification, if your device through the Microsoft test, you will be authorized to give you a PlaysForSure logo.
MTP in Android
MTP is full of media Transfer Protocol (Media Transfer Protocol), it is a set of Microsoft's proposed medium file Transfer protocol. Android supports MTP starting from 3.0. However, in today's smartphone world, Google and Microsoft are a pair of friends, why the use of MTP in Android. Please see below. A background knowledge introduction
I believe most readers of programmers magazine have used MTP more or less. As early as the popularity of smartphones, digital cameras and MP3 players, such as the use of MTP predecessor PTP (picture Transfer Protocol) for media file transfer. At that time, you could see these devices in my computer as long as they were connected to the Windows operating system via a USB cable. After that, users can use them as a USB flash drive, such as directory, file browsing and copying.
Since the smart device can be used as a USB flash drive with MTP, how is it different from our usual USB mass storage (USB Mass Storage, or UMS)? In UMS mode, the granularity of the PC operating storage device is the device block (FAT block), not the file system. What do you mean. Here is a simple example. When the Android phone is attached to the PC via UMS, the PC has absolute control over the SDcard. SDcard. This way, the phone will not be able to access sdcard at the same time. The result of this approach is that the camera or music program will not be able to operate because there is no external storage space (note that some manufacturers ' phones have been modified to allow the camera to record part of the video to internal storage for a short time). This is also an obvious feature in earlier versions of Android. Also, because the PC may break its file system when operating SDcard, this will cause the sdcard to be re-attached to the phone and not be recognized. If the Android phone's sdcard is attached to the PC in MTP mode, the control of the SDcard is still part of the phone. Only the smart phone has built a virtual file system to the PC via MTP protocol. When a PC operates a file, it initiates a request to the smartphone via the standard MTP protocol. In addition, Android integrates MTP functionality into the mediaprovider[1], and the benefits are that when PC operations (such as copying or deleting) media files, media data is updated to the media database in a timely manner. In UMS mode, when SDcard is mounted back to the phone, Android also takes a long time to rescan the media files to update the media database.
There are many benefits to MTP, such as the ability to determine whether a PC-copied media file is supported by the target phone, or even trigger the corresponding transcoding program to convert it to a phone-supported format. However, compared to UMS, MTP also has shortcomings: the transfer of large files is slower. MTP cannot directly modify the file itself. Can only be copied to local modifications, and then copied back. In addition to Windows, the MTP support for both Linux and MacOS is not perfect.
Below we will introduce the MTP protocol. 1.1 MTP Protocol Introduction
According to the agreement, the users of MTP include two parts, namely initiator and responder. As shown in Figure 1-1:
Figure 1-1 Initiator and responder illustration
Figure 1-1 shows: Initiator: Mainly refers to the USB Host, such as PC, Notebook and so on. The agreement stipulates that all MTP operations can only be initiated by Initator. Responder: Typically, devices such as digital cameras, smartphones, and other storage media files. The role of responder in MTP is to handle requests initiated by Initator. At the same time, it sends an event to notify initiator based on changes in its state.
Note: Later we will unify the PC on behalf of the Initiator,android mobile phone on behalf of responder.
As with many protocols, MTP has its own protocol stack, as shown in Figure 1-2:
Figure 1-2 MTP Protocol stack
As shown in Figure 1-2, the MTP stack is from bottom to top: pyshical layer (physical layer): the physical layer is used to transfer data in the MTP protocol. There are currently three physical layers available for MTP use. They are USB: The main feature is the transfer of files, synchronization of media files speed, and can work while charging, which is currently used the most one way; IP: An IP-based MTP (MTP/IP) will match and discover devices through UPnP. It is the most ideal transmission mode in the home network, BLUETOOTH:MTP/BT is the most power-saving, but also the slowest transmission mode, less useful. Transport layer: In MTP, the data transfer format follows the PTP Protocol command layer: implements the various commands in the MTP protocol.
As mentioned above, MTP uses command-response mode to work (Initator send commands to responder processing, responser feedback processing results), the main feature of this approach is: All MTP commands are delivered in the same way as the package (packet) on both ends of the device. The initiator must receive the result of the previous message (whether successful or timed out) before the next message can be sent.
Below we will take the PC through the MTP to open a file as an example, in order to describe which involves several major MTP commands: When the device is first connected to the PC, initiator (that is, the PC) first sends a request called Getdeviceinfo to obtain information about the device, This information includes the extent of the PTP version supported by the device, expressed as a percent sign (default is 100), the supported MTP commands (Operation supported), the supported event types, and so on. The PC-side then sends the opensession command to create a session that remains until the device disconnects from the PC. Thereafter all commands (except the Getdeviceinfo command) must survive this session to be sent. The session is identified by SessionID in the MTP protocol, which is a 32-bit unsigned integer that is selected by the PC and passed to the phone. PC side If you want to do file operation, you must locate the target file from the root directory. Due to the particularity of Windows, the phone's internal memory card is displayed as a drive letter in the Windows system. Note that if you have two memory cards inside your phone (such as an internal memory card and an external SD card), you will see two drive characters in Windows. The PC side needs to return the Storageid of a drive letter via the Getstorageids command. In MTP, Storageid is a 32-bit unsigned integer, and each Storageid represents a logical drive letter. The PC can use the Getstorageinfo operation to obtain information about the storage device, such as the remaining storage space, file system type, access rights, and so on, according to the Storageid number of the previous step. The PC then obtains the object Handles of the files and subdirectories under this drive by the Getobjecthandles command (an object handle represents a file or directory. This value is generated by responder and is guaranteed to be unique. With Object handle,pc, you can manipulate these files or directories, for example, continue to get information about sub-files and subdirectories in a directory through Getobjecthandles. If you need to copy a file to your phone now, the PC will pass the Sendobjectinfo command to the phone with the file information (such as filename, file size). The phone needs to check if the target directory has sufficient space and corresponding permissions. If everything works, the PC will pass the data to the phone via SendObject. The responder that actually writes the file to the device storage space is the phone. An MTP implemented by Android also updates the information to the media database after the media file has been transferred. In addition, the PC can also use SETOBJECTPROPVALUE  command to set various property values for a file, such as audio bitrate (bitrate), sample rate (sample rates), number of Channels (channel), etc.
The above describes a simple case for MTP use. As for the various MTP commands, readers may wish to read reference 1, "MTP specification V1.0.pdf". The protocol has a very precise description of the various commands, such as table 1-1, table 1-2, the Getdeviceinfo command, and the return value definition. The parameter type, the direction of delivery is explained in detail (it must be said, compared to Linux, Microsoft's Development/technical documentation is done quite well).
Table 1-1 getdeviceinfo Command definition
Operation Code |
0x1001 |
Getdeviceinfo the number of the corresponding command is 0x1001 |
Data |
DeviceInfo DataSet |
Device information data set returned by mobile phone |
Data Direction |
R->i |
Data transmission direction is mobile phone to PC |
Responsecode Options |
OK, parameter_not_supported |
The return value of the phone to the PC |
Table 1-2 shows the definition of the returned data set for Getdeviceinfo.
Table 1-2 Getdeviceinfo Returns the definition of a dataset
Dataset Field |
Field Order |
Size (bytes) |
Datatype |
Comments |
Standard Version |
1 |
2 |
UINT16 |
The level of support for the PTP protocol, expressed in%, by default is 100 |
MTP Vendor Extension ID |
2 |
4 |
UINT32 |
Mobile phone support for PTP Vendor extension protocol, default is 0xFFFFFFFF |
MTP Version |
3 |
2 |
UINT16 |
The version of the MTP standard supported by the phone, expressed in% |
MTP Extensions |
4 |
Variable |
String |
Supported MTP expansion sets for mobile phones |
Functional Mode |
5 |
2 |
UINT16 |
Allowed mode of mobile phone |
Operations supported |
6 |
Variable |
Operation Code Array |
All operations supported by the phone in the current feature mode |
|